robert_gsfame Posted March 25, 2010 Share Posted March 25, 2010 I have dynamic combobox below is the html code and javascript function show(){ if (document.form1.country.value == "Brazil"){document.getElementById('city').innerHTML = "<select name='mycity' id='mycity'><option value='ABC' id='ABC'>ABC</option></select>"} <form name="form1" method="post" action="<?php $_SERVER['PHP_SELF'];?>"> <select name="country"><option value="brazil" id="brazil" onchange= onchange="show()">Brazil</option> <div id="city"></div> </form> The problem is with the php code $country=$_POST['country']; $city=$_POST['mycity']; <--------------- no value how to solve this??thx in advance! Quote Link to comment https://forums.phpfreaks.com/topic/196457-post-problem/ Share on other sites More sharing options...
KevinM1 Posted March 25, 2010 Share Posted March 25, 2010 1. You need to tie your onchange event to the select element, not one of it's options. 2. You need to check it's selected index, not its value (google 'javascript select onchange' to see examples of what I mean). 3. You do have a submit button for your form, correct? You need a way to send the value to PHP. Quote Link to comment https://forums.phpfreaks.com/topic/196457-post-problem/#findComment-1031578 Share on other sites More sharing options...
robert_gsfame Posted March 25, 2010 Author Share Posted March 25, 2010 still unsolved, mind if you attach the sample of the code Quote Link to comment https://forums.phpfreaks.com/topic/196457-post-problem/#findComment-1031609 Share on other sites More sharing options...
KevinM1 Posted March 25, 2010 Share Posted March 25, 2010 Quick, dirty, and untested: <!DOCTYPE html> <html> <head></head> <body> <form name="form1" action="<?php echo $SERVER['PHP_SELF']; ?>" method="post"> <select name="country" id="country"> <option value="brazil">Brazil</option> </select> <div id="city"></div> <input type="submit" name="submit" value="Submit" /> </form> </body> <script type="text/javascript"> var oSelect = document.getElementById('country'); oSelect.onchange = function() { if (this.options[this.selectedIndex].value == 'brazil') { // do stuff } } </script> </html> Quote Link to comment https://forums.phpfreaks.com/topic/196457-post-problem/#findComment-1031630 Share on other sites More sharing options...
robert_gsfame Posted March 25, 2010 Author Share Posted March 25, 2010 thx Nightslyr, selectedindex.value really solve everything!!! Quote Link to comment https://forums.phpfreaks.com/topic/196457-post-problem/#findComment-1031642 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.