Help, I am trying to develop a form where the values are readonly until the user checks a checkbox to edit the row.

If I use a plain variable name uf_amount instead of an array variable name uf_amount[] it works fine.

I am including the whole page - sorry if it is too much. I am back to coding after having been away for 3 yrs.

Thanks,
Sonya

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<script	type="text/javascript">
<!-- Hide the script
    function SetState(obj_checkbox, obj_text)
    {  if(obj_checkbox.checked)
       {
			 // var ot = documents.forms[0].elements['uf_amount[]'];

		 obj_text.disabled = false;

   }
   else
   { obj_text.disabled = true;

   }
}
	 -->
</script>
<title>ck box test</title>
</head>
<body>
<?php
if ($submit)
{
 foreach( $_POST["lista"] AS $key => $value ) 
 {
	$new_amount = $_POST["uf_amount"][$key];
	$new_gml = $_POST["uf_gml"][$key];
	$uf_id = $_POST["uf_id"][$key];
	$user_id = "1";
	$updtsql = "UPDATE `user_food` SET `amount` = ' $new_amount ' AND  `g_ml` = ' $new_gml ' WHERE `uf_id` = ' $uf_id  ' AND `user_id` = '  $user_id ' LIMIT 1 ;";
 	echo "key is " . $key . " value is " . $value . "<BR>"; 
	echo "update sql is " . $updtsql . "<BR>";
	}
 } 
?>

<form action="<?echo $PHP_SELF?>" method="post">
pick a row <br>

<input name="lista[]" type="checkbox" value="0" onclick="SetState(this, this.form.['uf_amount'[]])">0
<input name="uf_id[]" type="hidden" value="33" />
<input name="uf_amount[]" type="text"  disabled />
<SELECT  name="uf_gml[]" disabled >
<option value="1">Grams</option>
<option value="2">ML</option>
</SELECT>
<br><input name="lista[]" type="checkbox" value="1">1
<input name="uf_id[]" type="hidden" value="33" />
<input name="uf_amount[]" type="text"  disabled />
<SELECT  name="uf_gml[]" disabled >
<option value="1">Grams</option>
<option value="2">ML</option>
</SELECT>

<br>
<input TYPE=submit NAME=submit VALUE=submit>
</form>



</body>
</html>

    I found the answer in another thread.

    For javascript use the id tag, for php the name tag. I write the array id into the id tag as the last value.

    Now it works.

    Sorry I did not mark where I found it to give the person credit.

    -Sonya

      Write a Reply...