ricky_vancouver Posted December 13, 2010 Share Posted December 13, 2010 This is a simply drop down box with three selections, one, two and three. while i try to select option two, i need a message box pop up showing two, if i select option three, the message box will show three. However i got the below error while i select it. Any problem with this simple codes ? Error: 'document.form1.select.value' is null or not an object ================================================================== <? print_r($_POST); print"<br>"; print_r($_GET);print"<br>"; $a = $_GET[select]; print $a; ?> <select name='select' onchange='go(this)'> <option value='one'>one</option> <option value='two'>two</option> <option value='three'>three</option> </select> <form name='form1'> <input type='hidden' name='txtSelect' value='select'> </form> <script type="text/javascript"> function go(opt) { var name = document.form1.select.value; alert (name); } </script> Quote Link to comment https://forums.phpfreaks.com/topic/221474-drop-down-list-problem/ Share on other sites More sharing options...
Adam Posted December 13, 2010 Share Posted December 13, 2010 You're passing the select object within the function parameters, so you don't need to reference the DOM path (document.form1.select.value) like you are doing. Just use the opt.value property within the function to get the value. By the way you're code would work if you moved the select element within the form tags (which you should move anyway to include them as part of the form), but as you're passing the object as I said, you shouldn't use the DOM path. Quote Link to comment https://forums.phpfreaks.com/topic/221474-drop-down-list-problem/#findComment-1146584 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.