I am having in a Trouble when working with dynamic checkboxes (i.e. checkboxes with the same name, e.g. <input type="checkbox" name = "check[]" value="dynamic integer value">)
I have submitted an HTML form (which contains dynamic textboxes and dynamic checkboxes with a Post Button(input type="button")) by using Ajax function. (onClick="return ajaxFunction(document.getElementById('formid'));")
In the ajax function, i have collected all form in a single javascript variable named 'formdata' as shown below :
------------
Expand|Select|Wrap|Line Numbers
- for (i=0; i < theForm.length; i++)
- {
- if(theForm.elements[i].type == "text") { //Handle Textbox's
- formdata = formdata + theForm.elements[i].name + "=" + escape(theForm.elements[i].value) + "&";
- }
- else if(theForm.elements[i].type == "checkbox" ) { //Handle checkbox's
- formdata = formdata + theForm.elements[i].name + "=" + theForm.elements[i].value + "&";
- }
i have passed this 'formdata' variable as an argument to the ajax function, which post all form data to a processing php page (i.e. process.php) and this page processes the data and send back HTTPResponse to the first page which contains that html form.
I am getting that all ajax Request and Response are working properly, but i m regularly receiving (in process.php) all checked and "UNCHECKED" both checkboxes' name and value in the Post data array, here i expect to receive ONLY CHECKED checkboxes in that Post data array.
I think, my javascript codes (shown above) is giving such unwanted result, Could you plz suggest me, how can i solve this problem ???
Thanks in advance,
Sunbin