mraza Posted August 2, 2010 Share Posted August 2, 2010 hi i need a little help with javascript, I have one drop downl list which is populating from mysql <script type="text/javascript"> function show() { // dont know what to put here :-\ } <script> <select name="user" onchange="show()"> <option value="0">Select a user </option> <option value="1">First Name of one user </option> <option value="2">First Name of second user</option> <option value="3">First Name of third user</option> </select> <input type="text name="fname" value="" /> Now what i wants is when i change first option to second it will fill value="" of input box with that user second name which i need to run mysql query but i am not good with javascript so really appreciate for any help. Thanks Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted August 2, 2010 Share Posted August 2, 2010 Try something like this, not tested: <script type="text/javascript"> function updateUser(obj) { var selected = obj.options[obj.options.selectedIndex].value; document.getElementById('fname').value = selected; if(selected == 0){ document.getElementById('fname').value = ''; } } </script> <select name="user" onchange="javascript: updateUser(this)"> <option value="0">Select a user </option> <option value="firstname1">First Name of one user </option> <option value="firstname2">First Name of second user</option> <option value="firstname3">First Name of third user</option> </select> <input type="text" id="fname" name="fname" value="" /> What I did was change the dropdown box so that the value of each option is also the username, so that you can grab the value. Didn't test it, just going from memory really. I tend to use JavaScript frameworks these days anyway. 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.