Pass the value with checkbox using AJAX

Hello,

I want to pass value through AJAX using checkboxes. but i wanted to add one more condition here and that is if it is already marked then go to one file(deletion) or if its unmarked go to different file and that is to be insertion file.

Here is my code

php

<li style="list-style:none;"><span><input type="checkbox" name="checkbox[]" value="<?=$fruitname?>" id="<?=$fruitname?>"  checked="checked" <?php if($fruitname !=''){ echo "checked=\\"true\\""; }?> onclick="javascript:return insert1('<?=$fruitname?>');">
		<?=$fruitname;?></span></li></ul>

JS

function insert1(fruitname){
alert(fruitname);
  if (fruitname.checked == 1)
 {   
    alert("Thank You");
  http.open('get', 'deletelist.php?fruitname='+fruitname);
}
  else{
  http.open('get', 'insert_try.php?fruitname='+fruitname);

    alert("You didn't check it! Let me check it for you.")
     fruitname.checked = 1;
}}


Can anyone please tell ,is this the right method to do this?

Thanks in advance.

function insert1(fruitname){
alert(fruitname);
  if ([COLOR="Navy"]document.getElementById(fruitname).checked[/COLOR])
 {   
    alert("Thank You");
  http.open('get', 'deletelist.php?fruitname='+fruitname);
}
  else{
  http.open('get', 'insert_try.php?fruitname='+fruitname);
 
    alert("You didn't check it! Let me check it for you.")
     [COLOR="Navy"]document.getElementById(fruitname)checked = true;[/COLOR]
}}

Also in the php you use: echo “checked=\“true\””; which is incorrect.
Use <input type=“checkbox” checked=“checked” /> in xhtml
and <input type=“checkbox” checked> in html

Thanks a lot dogFang,

Its working like charm!!!

Many many many thanks to you. :D:D:D