scarhand Posted January 22, 2009 Share Posted January 22, 2009 dynamic checkboxes are not posting. i know this because i am trying to echo the ones i select, and they are not echoing. heres my code: AJAX in assign.php: function ajaxfunction() { var ajaxrequest; try { ajaxrequest = new XMLHttpRequest(); } catch (e) { try { ajaxrequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { ajaxrequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { alert("Browser does not support HTTP requests."); return false; } } } return ajaxrequest; } function statechanged() { if (htmlrequest.readyState==4) { document.getElementById("citydiv").innerHTML = htmlrequest.responseText; } } function showcities(state) { htmlrequest = ajaxfunction(); if (htmlrequest==null) { alert ("Browser does not support HTTP requests."); return; } var querystring = "?state=" + state; htmlrequest.onreadystatechange=statechanged htmlrequest.open("GET", "assign_cities.php" + querystring, true); htmlrequest.send(null); } PHP in assign.php: if (isset($_POST['assign_x'])) { $citya = array(); foreach ($_POST as $field => $value) { $$field = mysql_real_escape_string(trim($value)); echo $field . '<br />'; } } FORM in asign.php: <body onload="showcities(document.getElementById('stateselect').value)"> <form method="post"> <select name="state" style="width: 400px;" id="stateselect" onchange="showcities(this.value)"> <?php $sql = mysql_query("SELECT * FROM ass_states ORDER BY statename ASC"); while ($row = mysql_fetch_array($sql)) { $state = $row['statename']; echo "<option value=\"$state\">$state</option>"; } ?> </select> <div id="citydiv"></div> </form> </body> PHP in assign_cities.php: $state = $_GET['state']; $sql = mysql_query("SELECT * FROM ass_cities WHERE state='$state' ORDER BY cityname ASC"); while ($row = mysql_fetch_array($sql)) { $city = $row['cityname']; $csql = mysql_query("SELECT * FROM ass_city WHERE city='$city'"); if (mysql_num_rows($csql) == 0) echo "<input type=\"checkbox\" value=\"$city\"> $city<br />"; else echo "<input type=\"checkbox\" value=\"$city\" disabled> <font style=\"color: #999999;\">$city</font><br />"; } help Link to comment https://forums.phpfreaks.com/topic/141961-solved-dynamic-checkboxes-are-not-posting/ Share on other sites More sharing options...
satishgadhave Posted January 22, 2009 Share Posted January 22, 2009 Hi, try using this code to echo submitted values (I have changed $$field to $field): if (isset($_POST['assign_x'])) { $citya = array(); foreach ($_POST as $field => $value) { $field = mysql_real_escape_string(trim($value)); echo $field . '<br />'; } } Link to comment https://forums.phpfreaks.com/topic/141961-solved-dynamic-checkboxes-are-not-posting/#findComment-743551 Share on other sites More sharing options...
scarhand Posted January 24, 2009 Author Share Posted January 24, 2009 i sorted it out it was because i was using "value" instead of "name" for the checkboxes you changing "$$field" to "$field" would accomplish nothing. in fact, it would render any variables i used below useless. Link to comment https://forums.phpfreaks.com/topic/141961-solved-dynamic-checkboxes-are-not-posting/#findComment-745079 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.