ahs10
2008-Jan-17 04:12 UTC
trying to get the value of checked checkboxes passed through ajax
i think i may be thinking this too hard, but here''s what i''ve come up with that doesn''t work. i have an undefined amount of checkboxes in the document below that are generated by php during a while loop. that loop gives each one a unique id (check0, check1, check2, etc). i''m trying to initiate an ajax request, but in it''s parameters send a variable that contains a list of all the checked checkboxes. my php of the ajax request (i put spaces between '' and " next to each other for display here).... function assignUser(userName) { var searchCount=<?php echo $searchCount; ?> <?php $t = "var checkBoxNames='' "; for ($i = 0; $i < $searchCount; $i++) { $t .= "check" . $i . "~"; } $t .= " '' "; echo $t; ?> var tSplit=checkBoxNames.split(''~'') var checkedYes='''' for (var j = 0; j < searchCount; j++) { var tj=tSplit[j] if (document.getElementById(tj).checked) { checkedYes=checkedYes+''~''+tj } } new Ajax.Request(''../php/assignUser.php'', { method:''post'', parameters: {userName: userName, location: location, checkedYes: checkedYes}, onSuccess: function(transport) { document.title="Records Successfully Assigned" new Effect.BlindUp(''adminAssign''); document.getElementById(''dynaDiv_searchResults'').innerHTML=transport.responseText }, onFailure: function() { alert(''Ruh Roh!''); } }); } which outputs this in the source.... function assignUser(userName) { var searchCount=14 var checkBoxNames=''check0~check1~check2~check3~check4~check5~check6~check7~check8~check9~check10~check11~check12~check13~'' var tSplit=checkBoxNames.split(''~'') var checkedYes='''' for (var j = 0; j < searchCount; j++) { var tj=tSplit[j] if (document.getElementById(tj).checked) { checkedYes=checkedYes+''~''+tj } } new Ajax.Request(''../php/assignUser.php'', { method:''post'', parameters: {userName: userName, location: location, checkedYes: checkedYes}, onSuccess: function(transport) { document.title="Records Successfully Assigned" new Effect.BlindUp(''adminAssign''); document.getElementById(''dynaDiv_searchResults'').innerHTML=transport.responseText }, onFailure: function() { alert(''Ruh Roh!''); } }); } my idea here is to send the checkedYes variable as a parameter with the request. it would be a string containing the list of checked checkboxes, separated by a ~ which i could explode in the php that receives the request. it doesn''t work. when i click on the button that runs this function and supplies the user name, nothing happens. i stuck an alert(''i am here''); at the very beginning of the function, tried it and it didn''t give me a popup either. besides the fact that my mind leans towards the server side....what''s wrong? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---