Jump to content

[SOLVED] using a value from a select box in a javascript variable


simon551

Recommended Posts

trying to take the value from a select box and use it in a js variable. any suggestions?

 

      <td nowrap align="right">Default Currency </td>
      <td><select name="curr" id="curr">
        <option value="USD">USD</option>
        <?php
do {  
?>
        <option value="<?php echo $row_rsCurr['CurrCode']?>"><?php echo $row_rsCurr['CurrCode']?></option>
        <?php
} while ($row_rsCurr = mysql_fetch_assoc($rsCurr));
  $rows = mysql_num_rows($rsCurr);
  if($rows > 0) {
      mysql_data_seek($rsCurr, 0);
  $row_rsCurr = mysql_fetch_assoc($rsCurr);
  }
?>
      </select></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Amount Exchanged (USD) </td>
      <td><input type="text" name="textfield" /></td>
     </tr>
<script type="text/javascript">
var currname=this.form.curr.value
</script>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Amount Recieved (<script type="text/javascript"> document.write(currname)</script>) </td>

Link to comment
Share on other sites

Thanks for the reply. Trying this:

	<script type="text/javascript">
var currname=document.getElementById('curr').value;
</script>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Amount Recieved (<script type="text/javascript"> document.write("currname")</script>
      ) </td>

 

Link to comment
Share on other sites

also trying this. Trying to call the function:

<select name="curr" id="curr" onchange=writeCurrName;>

 

The function:

	<script type="text/javascript">
function writeCurrName(){
var currname=document.getElementById('curr').value;
document.getElementById("amtrecmsg").innerHTML = "Currency Recieved (" +currname + ")";
}
	</script>

 

And just so I'm not leaving anything out, the field to change:

<td nowrap="nowrap" align="right" id="amtrecmsg">

Link to comment
Share on other sites

Just in case anyone is trying to do this, I figured it out. I put the script in a separate file and called it within the script rather than trying to call it from the onchange in the form, and it works now. Not exactly sure why. btw: does anyone know of a more active javascript forum?

window.onload=writeCurrName;

//the following function does the work: creates the string to be placed into the lable field and sets up the field
function getname(currname){
var currname=document.getElementById('curr').value;
			document.getElementById("amtrecmsg").innerHTML = "Currency Recieved (" + currname + ")";

}
//this is the trigger
function writeCurrName(){
document.getElementById("curr").onchange=getname;
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.