SitePoint Sponsor |
|
User Tag List
Results 1 to 6 of 6
Thread: ajax checkboxes
-
Nov 22, 2007, 10:27 #1
- Join Date
- Feb 2007
- Posts
- 402
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
ajax checkboxes
Hi..
I am trying to implement a system like googlemail where emails are removed using AJAX.
I am using the prototype library here....
I have my emails displayed in a HTML table, which is wrapped in a form
HTML Code:<form name="ajaxmail"> <table id="emails"> <thead> <tr> <th>Name</th> <th>Delete</th> <th><a href="#" onclick="delete_emails()">delete</a></th> </tr> </thead> <tbody> <cfoutput> <tr> <td>#emailname#</td> <td>#subject#</td> <td><input type="checkbox" name="MessageNumber" value="#MessageNumber#" id="MessageNumber"><label for="#MessageNumber#">Delete #MessageNumber#</label></td> </tr> </cfoutput> </tbody> </table> </form>
Code:function delete_emails() { var messagenumber = $F('MessageNumber'); var url = '/ajax/emails_remove.cfm'; var pars = 'messagenumber='+ messagenumber; var target = 'delete_success'; var myAjax = new Ajax.Updater(target, url, {method:'post', parameters:pars}); }
then the action page for the ajax "emails_remove.cfm", which contains the code to remove the relevant email by the id....
HTML Code:<!--- contact POP server and delete the message ---> <cfpop action="delete" messagenumber="#FORM.messagenumber#" server="mail.musicexplained.co.uk" username="namtax@musicexplained.co.uk" password="dryryzer">..
Hope this makes sense, any help would be appreciateddiscover song meanings and more http://www.music-explained.com
-
Nov 26, 2007, 02:18 #2
- Join Date
- Feb 2007
- Posts
- 402
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
been looking around on the net about this
i think i need to pass the ids of the checked checkboxes as a javascript array, and then convert the array, so coldfusion can deal with it on the database side..unsure of how to create the javascript array however...discover song meanings and more http://www.music-explained.com
-
Nov 26, 2007, 04:30 #3
- Join Date
- Oct 2006
- Location
- Kathmandu, Nepal
- Posts
- 4,013
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I am not sure passing the Array variable through, but you can collect the checked email ids into a hidden element separated with commas and pass this through AJAX to your coldfusion page. And split the ids into an array then you can delete in loop. I am not sure how the coldfusion code will be for that.
Mistakes are proof that you are trying.....
------------------------------------------------------------------------
PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5
-
Nov 26, 2007, 12:03 #4
- Join Date
- Feb 2007
- Posts
- 402
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
hi, rajug.
How would you collect the checked email ids into a hidden element and pass this to the coldfusion page..
Have you managed to do something similar with PHP?
Thanksdiscover song meanings and more http://www.music-explained.com
-
Nov 27, 2007, 04:41 #5
- Join Date
- Oct 2006
- Location
- Kathmandu, Nepal
- Posts
- 4,013
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi namtax!
This is the JS and HTML code to to collect the ids. I have used PHP for creating dynamic form. I hope you can understand.
HTML Code:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Checkbox</title> <script language="javascript" type="text/javascript"> function CollegeID(obj){ var frm = document.frm; var currentids = frm.ColletedIDs.value; var newids = ""; if(obj.checked == true){ if(currentids.length == 0) frm.ColletedIDs.value = obj.value; else frm.ColletedIDs.value = currentids + "," + obj.value; } else if(obj.checked == false){ var arrIds = currentids.split(/,/); for(var i = 0; i < arrIds.length; i++){ if(arrIds[i] != obj.value){ if(newids.length == 0) newids = arrIds[i]; else newids = newids + "," + arrIds[i]; } } frm.ColletedIDs.value = newids; } } </script> </head> <body> <form name="frm" id="frm" method="post" action=""> <strong>Collected ID: </strong> <input type="text" name="ColletedIDs" id="ColletedIDs" style="width:200px;" /><br /> <strong>Messages:</strong><br /> <?php $ArrMessage = array(1=>'Message 1', 2=>'Message 2', 3=>'Message 3', 4=>'Message 4', 5=>'Message 5', 6=>'Message 6', 7=>'Message 7'); foreach($ArrMessage as $msgid=>$message){ ?> <input type="checkbox" name="id[]" id="id[]" onClick="CollegeID(this);" value="<?php echo $msgid;?>" /> <?php echo $message;?><br /> <?php } ?> <input type="submit" name="submit" id="submit" value="Submit" /> </form> </body> </html>
Feel free to PM if you need further help.
Good luck!Mistakes are proof that you are trying.....
------------------------------------------------------------------------
PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5
-
Nov 27, 2007, 14:10 #6
- Join Date
- Feb 2007
- Posts
- 402
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
magnificent...have got that to work..
Thank you muchly..discover song meanings and more http://www.music-explained.com
Bookmarks