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> <input type="submit" value="submit> </form> The problem is with the php code $country=$_POST['country']; $city=$_POST['mycity']; <--------------- no value how to solve this??thanks in advance! Link to comment https://forums.phpfreaks.com/topic/196483-no-value-when-using-onchange-event/ Share on other sites More sharing options...
JustLikeIcarus Posted March 26, 2010 Share Posted March 26, 2010 this is because you are adding the mycity select box to the dom dynamically so it will not exist when a post is performed. One way to solve this is to have a hidden input element and set its value to the selected value in the dropdown via js then reference the hidden element in the php to get the value. Any time you add a form element after the dom has loaded it wont be seen by the browser when the form is submitted. Link to comment https://forums.phpfreaks.com/topic/196483-no-value-when-using-onchange-event/#findComment-1032041 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.