I have php displaying a dropdown box with list of rows in mysql database. On dropdown select of an option I want a javascript variable to be define with the value in the mysql row selected. Is this possible in one query? Thanks
something like this ... <html> <head> <script type="text/javascript"> function assignVar() { var myObj = document.getElementById("mySelect"); myVar = myObj.options[myObj.selectedIndex].text; // do whatever ... alert(myVar); } </script> </head> <body> <form method="POST" action=""> <select id="mySelect" size="1" name="mySelect" onchange="assignVar()"> <option>choose ...</option> <option>this</option> <option>that</option> <option>then</option> <option>there</option> </select> </form> </body> </html> Code (markup):
you can use "this.value" when you are calling the function as selected value <script language="Javascript"> function assignVar(selected) { doSomething() } </script> HTML: <select id="mySelect" size="1" name="mySelect" onchange="assignVar(this.value)"> <option>choose ...</option> <option>this</option> <option>that</option> <option>then</option> <option>there</option> </select> HTML: