Jump to content

Archived

This topic is now archived and is closed to further replies.

scarhand

[SOLVED] dynamic checkboxes are not posting.

Recommended Posts

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

Share this post


Link to post
Share on other sites

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 />';
  }
}

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.