deepson2 Posted November 20, 2009 Share Posted November 20, 2009 Hello, I am trying to insert the value when clicks on the checkbox value And i am perfectly able to achieve this with the help up this forum only. I would like to show here the code to get an perfect idea about it my code is bellow- onclick.js function insert(fruitname,pid) { document.getElementById('insert_response').innerHTML = "Just a second..." nocache = Math.random(); //alert("hello"); // Pass the login variables like URL variable http.open('get', 'insert.php?fruitname='+fruitname+'&pid='+pid+'&nocache = '+nocache); http.onreadystatechange = insertReply; http.send(null); } index.php <div id="insert_response"></div> <li style="list-style:none;"><span><input type="checkbox" name="checkbox[]" value="<?=$fruitname?>" <?php if($fruitname=='1'){ echo "checked=\"true\""; }?> onclick="javascript:return insert('<?=$fruitname;?>','<?=$pid;?>');"><?=$fruitname;?></span></li> when i refresh that page i can see the checked mark on the fruitname which i have added using the above method. Now what i want to do is, if i unchecked that fruitname then it should get deleted from my list. for that i was trying something like this onclick1.js function insert(fruitname,pid) { document.getElementById('insert_response').innerHTML = "Just a second..." nocache = Math.random(); //alert("hello"); // Pass the login variables like URL variable if(document.listform.fruitname.checked == true) { http.open('get', 'delete.php?fruitname='+fruitname+'&pid='+pid+'&nocache = '+nocache); }else{ http.open('get', 'insert.php?fruitname='+fruitname+'&pid='+pid+'&nocache = '+nocache); } http.onreadystatechange = insertReply; http.send(null); } index1.php <form name="listform" action="<?$PHP_SELF;?>" method="post"> <? if($check == 1) { ?> <div id="insert_response"></div> <li style="list-style:none;"><span><input type="checkbox" name="checkbox[]" value="<?=$list_name?>" checked="checked" <?php if($fruitname=='1'){ echo "checked=\"true\""; }?> onclick="javascript:return insert('<?=$fruitname;?>','<?=$pid;?>');"> <?=$list_name;?></span></li> <?} elseif($check == 0) { ?> <div id="insert_response"></div> <li style="list-style:none;"><span><input type="checkbox" name="checkbox[]" value="<?=$fruitname?>" <?php if($list_name=='1'){ echo "checked=\"true\""; }?> onclick="javascript:return insert('<?=$fruitname;?>','<?=$pid;?>');"> <?=$fruitname;?></span></li> <?} else { } ?> </form> So my problem is how can i check my value is checked or not and accordingly apply the insert or delete query pages respectively? Any help would be highly appreciated. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/182261-on-click-of-checkbox-insert-the-value-or-delete-value/ Share on other sites More sharing options...
JustLikeIcarus Posted November 20, 2009 Share Posted November 20, 2009 I would use jQuery personally. Give the checkbox an id like "fruit" and then the js would be: if ($('#fruit').is(':checked')){ // code here } Quote Link to comment https://forums.phpfreaks.com/topic/182261-on-click-of-checkbox-insert-the-value-or-delete-value/#findComment-961917 Share on other sites More sharing options...
deepson2 Posted November 21, 2009 Author Share Posted November 21, 2009 I would use jQuery personally. Give the checkbox an id like "fruit" and then the js would be: if ($('#fruit').is(':checked')){ // code here } Thanks for your reply JustLikeIcarus well, many be i could use jquery, but again i am passing two values function insert(fruitname,pid) { and then how can i separate out the both the values so i can check only my fruitname value. Just a curiosity with simple JS, can we do that? please help me. Quote Link to comment https://forums.phpfreaks.com/topic/182261-on-click-of-checkbox-insert-the-value-or-delete-value/#findComment-962379 Share on other sites More sharing options...
deepson2 Posted November 21, 2009 Author Share Posted November 21, 2009 I am getting null value for my id. here is my code. function insert1(){ var browser = document.getElementById('fruitname'); alert(browser); var browser1 =document.getElementByID('blog_id'); if(document.getElementById('fruitname').checked == true) { http.open('get', '../../ib/deletelist.php?list_name='+fruitname); }else{ http.open('get', '../../ib/insert.php?list_name='+fruitname); } } Still no luck. Actually i trying to build up system exactly like twitter's list. if you want follow particular list you just need to click on list button then you ll get checkbox with your list names. so if you click that checkbox it ll get added into that particular list and once you remove the checkbox mark it ll get deleted form your list. for this we can say that i am able to do it till insertion part. but still having hard time with the both methods. please help me. Quote Link to comment https://forums.phpfreaks.com/topic/182261-on-click-of-checkbox-insert-the-value-or-delete-value/#findComment-962421 Share on other sites More sharing options...
deepson2 Posted November 23, 2009 Author Share Posted November 23, 2009 Any help?? Quote Link to comment https://forums.phpfreaks.com/topic/182261-on-click-of-checkbox-insert-the-value-or-delete-value/#findComment-963747 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.