I'm trying to provide a method for users to edit their address book. I show a list of shipping addresses and buttons. The idea is that the user clicks on the button next to the address they want to edit.
I'm using an array to capture the variable needed. I'm putting the loop in a form so I can use a button to take that variable into a javascript function. In the function I will drop a cookie and go into another page for editing. In that second page, I would retrieve the entry to be edited and delete the cookie.
I thought this a great plan, except that it doesn't work. Nothing happens when the button is clicked. I have no clue why. Do I have a bug? Do I need a whole new plan. Can anyone advise? Below is the javascript function and the form containing the loop printing out shipping addresses.
Thanks for any direction or comments.
<script language="javascript">
var des;
function EditAddress(des){
alert(got this far);
<?php //drop a cookie holding des value
?>
document.AddressForm.action= '<?=$secure_address."/".$page_addressbooks ?>';
document.AddressForm.submit();
exit;
}
</script>
<table width="100%" border="0" cellspacing="0" cellpadding="2" align="center">
<tr><td><br></td></tr>
<?php
$query = "SELECT * FROM addressbooks WHERE username = '$username'";
mysql_select_db($dbDatabase2,$GLOBALS['dbLinkSession']);
$result = mysql_query($query,$GLOBALS['dbLinkSession']);
if($result && (mysql_numrows($result) >1 )){
$i = 0;
while($data=mysql_fetch_array($result)) {
$i = $i + 1;
$description = $data['description'];
$des[$i] = $description;
$shipping_first_name = $data['shipping_first_name'];
$shipping_last_name = $data['shipping_last_name'];
// php other variable inserted here
?>
<tr><td><div align="center"><strong><?php echo $description ?> </strong></div></td><td><div align="center">
<input type="button" class="buttonControl1" value="Edit This Address" onClick="EditAddress('$des[$i]')" id="EditAddress">
</div></td></tr>
<tr><td><div align="center"><?php echo $shipping_first_name ?> </div></td><td><div align="left"></div></td></tr>
<tr><td><div align="center"><?php echo $shipping_last_name ?> </div></td><td><div align="center"></div></td></tr>
<?php }
} ?>
</table></form>