PDA

View Full Version : ajax is resetting form with each update


matthewst
05-07-2010, 08:28 PM
I have XMLHttpRequest working. The problem is when a user selects a checkbox in my form the next refresh clears it.

echo "<form name='mark_sold' action='mark_sold.php' enctype='multipart/form-data' method='post'><table width='1100' border='1'><tr><td><h2>Spot 1</h2>";
foreach ($rest_ids as $id){
//$rest_ids = implode("' or '", $rest_ids);
//$rest_ids = "'" . $rest_ids . "'";
$Get_Ad = mysql_query("SELECT rest_id, rest_name, city, ad_space1 FROM restaurant_info WHERE rest_id = $id");
$got_ad = mysql_fetch_assoc($Get_Ad);
$is_sold = $got_ad['ad_space1'];
$rest_id = $got_ad['rest_id'];
$rest_name = $got_ad['rest_name'];
$city = $got_ad['city'];
if($is_sold){
$is_sold = "<font color='red'>sold</font><input name='ad1' type='hidden' value='1' /><input name='rest_id' type='hidden' value='" .$rest_id."' />";
}else{
$is_sold = "<font color='green'>available</font><input name='ad1' type='checkbox' value='1'/><input name='rest_id' type='hidden' value='" .$rest_id."' />";
}
echo $rest_name." in ". $city." is ".$is_sold."<br />";
}
echo "</td><td><h2>Spot2</h2>";

How do I maintain the new checks or radio button selections while updating with ajax?

matthewst
05-10-2010, 01:10 PM
Certainly someone knows how to do this. I just need to keep new form entries while ajax checks the database for updates.

What if I had an onclick on my checkboxes that would alert a checkbox monitering page. Then after each ajax refresh the monitering page would kick in and maintain all my checks.

Anyone know how to do that? It's above my head.

matthewst
05-10-2010, 02:56 PM
I've found this (http://www.webdeveloper.com/forum/showpost.php?p=892217&postcount=6) on webdeveloper but can't get it to work either.

matthewst
05-10-2010, 05:13 PM
I added this to my ajax page:
function setVariable(ad1) {
var _form = document.getElementById("ad1");
_form.ad1 = 1;
}

and this to my php page:
$is_sold = "<font color='green'>available</font><input name='ad1' id='ad1' type='checkbox' value='1' onClick=\"setVariable('<?$ad1 = '1'?>');\"/><input name='rest_id' type='hidden' value='" .$rest_id."' />"; ~ notice the onClick event is new.

I've added an echo to my php page:
if ($ad1 = '1'){
echo ":)";}
else
{echo ":(";} ~ poor guy never smiles

I'm going to set it up so that if $ad1 - 1 than $is_sold = "blah blah checkbox is checked"



Still no luck. I just need this form to remember which boxes are ticked between ajax refreshes. Is this truly impossible?