Jump to content

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.