Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3359290
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:51:16+00:00 2026-05-18T02:51:16+00:00

I am trying to pass a value to a global variable. This is where

  • 0

I am trying to pass a value to a global variable. This is where shdivs() is initialized:

<select id="currentq" onchange="shdivs();">

getElementById(‘currentq’) gets div ids. The idea is that when there is a change in the select box, old div is hidden, new one is shown. However the alerts change for the div I want to be shown (qwe changes appropriately), but the ‘old’ var is not changed. So when I select different things from the list I get things like:

alert:SMT alert:AUS Select again
alert:SMT alert:USD

Which means that variable ‘old’ is not updated.

old="SMT";
    function shdivs() {
        alert(old);
        qwe=document.getElementById('currentq').value;
        alert(qwe);
        document.getElementById(qwe).style.visibility="visible";
        document.getElementById(old).style.visibility="hidden";
        old=qwe;
    }

Can someone tell me what the problem is ?

Entire HTML/PHP/JavaScript Code:

<?
echo '<script language="JavaScript">
<!--
    var rate = new Array(1,';
    $rows = simplexml_load_file('cron/ecbrates.xml');
    foreach($rows->Cube->Cube->Cube as $rate){
        if ($rate["currency"]=="BGN") echo $rate["rate"].',';
    }
        foreach($rows->Cube->Cube->Cube as $rate){
        if ($rate["currency"]=="USD") echo $rate["rate"].',';
    }
        foreach($rows->Cube->Cube->Cube as $rate){
        if ($rate["currency"]=="GBP") echo $rate["rate"].',';
    }
        foreach($rows->Cube->Cube->Cube as $rate){
        if ($rate["currency"]<>"BGN" && $rate["currency"]<>"USD" && $rate["currency"]<>"GBP")
            if($rate["currency"]=="ZAR") echo $rate["rate"];
            else echo $rate["rate"].',';
    }
    echo ');
    function currency_convert(origin) {
        var origin_value = eval(\'document.currency.c\'+origin+\'.value\');
        var euro_equivalent = rate[origin];
        var v;
        for (i=0; i<rate.length; i++) {
            if (i!=origin) {
                v = Math.round(rate[i]*origin_value/euro_equivalent*10000)/10000;
                eval(\'document.currency.c\'+i+\'.value = \'+v);
            }
        }
        return true;
    }
// -->
</script>';
?>
<div style="position:relative;">
<form name="currency">
<table cellspacing="0" cellpadding="0" border="1" bordercolor="#336699">
<tr><tr>
<td><img src="flags/eur.jpg" alt="Europe" width="30" height="20"></td>
<td>EUR</td>
<td><input type="text" name="c0" value="" size="10" onKeyUp="currency_convert(0);"></td></tr><tr>
<td><img src="flags/bgn.gif" alt="USA" width="30" height="20"></td>
<td>BGN</td>
<td><input type="text" name="c1" value="" size="10" onKeyUp="currency_convert(1);"></td></tr><tr>
<td><img src="flags/usd.gif" alt="Austria" width="30" height="20"></td>
<td>USD</td>
<td><input type="text" name="c2" value="" size="10" onKeyUp="currency_convert(2);"></td></tr><tr>
<td><img src="flags/gbp.gif" alt="Belgium" width="30" height="20"></td>
<td>GBP</td>
<td><input type="text" name="c3" value="" size="10" onKeyUp="currency_convert(3);"></td></tr><tr>
<td colspan="2">
<select id="currentq" onchange="shdivs();">
<?
foreach($rows->Cube->Cube->Cube as $rate){
    if ($rate["currency"]<>"BGN" && $rate["currency"]<>"USD" && $rate["currency"]<>"GBP") {
        echo '<option value="'.$rate['currency'].'">'.$rate['currency'].'</option>';
    }
}
?>
</select>
</td>
<td>
<?
$numb=4;
foreach($rows->Cube->Cube->Cube as $rate){
    if ($rate["currency"]<>"BGN" && $rate["currency"]<>"USD" && $rate["currency"]<>"GBP") {
        echo '<div style="position:absolute; top:99px; visibility:hidden;" id="'.$rate["currency"].'"><input type="text" id="'.$rate["currency"].'" name="c'.$numb.'" value="" size="10" onKeyUp="currency_convert(4);"></div>';
        $numb++;
    }
}
?>

    </td>
</tr></table>
</form>
</div>
<script type="text/javascript">
    old="SMT";
    function shdivs() {
        alert(old);
        qwe=document.getElementById('currentq').value;
        alert(qwe);
        document.getElementById(qwe).style.visibility="visible";
        document.getElementById(old).style.visibility="hidden";
        old=qwe;
    }
    </script>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T02:51:16+00:00Added an answer on May 18, 2026 at 2:51 am

    The best possible explanation for this is that one of the following two lines are failing.

        document.getElementById(qwe).style.visibility="visible";
        document.getElementById(old).style.visibility="hidden";
    

    Can you verify that there all the IDs referenced by your select exist in the DOM?

    Move the alert to the end of the function, and see if it pops up when you run it again.

    EDIT

    Since you posted the entire code, I can see a potential issue.

    In the code that writes the DIV, you have assign the same id to two elements. An ID should be unique:

     ...id="'.$rate["currency"].'"><input type="text" id="'.$rate["currency"].'" name="c'.$numb.'"...
    

    Unrelated

    Little tip for you. If you pass this in the onchange parameters, you don’t have to getElementById on the select:

    function shdivs(objcurrentq) {
        qwe=objcurrentq.value;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to pass the name of a global variable to a sub routine
I'm trying to pass a null value for the first parameter in the code
I'm currently trying to pass a mono threaded program to multithread. This software do
I am trying to pass a member function within a class to a function
I'm trying to pass in a Base64 string into a C#.Net web application via
I'm trying to pass one method to another in elisp, and then have that
I am trying to pass some Subsonic collections to a client via a web
I'm trying to pass a complex object (that can be serialized, if that helps)
I am trying to pass a dataString to to an ajax call using JQuery.
I'm trying to pass an instance of a class between two separate classes, like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.