simon551 Posted May 12, 2007 Share Posted May 12, 2007 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> Quote Link to comment Share on other sites More sharing options...
emehrkay Posted May 12, 2007 Share Posted May 12, 2007 var jsVariable = document.getElementById('curr').value; you need to trigger that action though, show us your js code Quote Link to comment Share on other sites More sharing options...
simon551 Posted May 15, 2007 Author Share Posted May 15, 2007 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> Quote Link to comment Share on other sites More sharing options...
simon551 Posted May 15, 2007 Author Share Posted May 15, 2007 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"> Quote Link to comment Share on other sites More sharing options...
simon551 Posted May 15, 2007 Author Share Posted May 15, 2007 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; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.