Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ajax, posting multiple checkbox values 1

Status
Not open for further replies.

snowboardr

Programmer
Feb 22, 2002
1,401
PH
I am trying to post multiple checkbox values... (they all have the same name different value) but its not working... IE says Object expected
I have checked my form names / ids etc... I have tried different methods to return the values... but its not working.

Regards


Code:
	function status(intstatus)
	{ 
	var str = "id=" + document.getElementById('mailchecks2') + "&status=" + intstatus; 
	var url = "/ajax/mail/mail_status.asp";
	xmlHttp=createRequestObject()
	xmlHttp.open("POST",url,true);
  	xmlHttp.setRequestHeader("Content-Type","application/x-[URL unfurl="true"]www-form-urlencoded;[/URL] charset=UTF-8");
	xmlHttp.send(str);
	LoadMAILHtml('0');
	}
 
I didn't know you could submit multiple checkboxes with the same name. I usually do it with an array name in html
Code:
<input type="checkbox" id="mumu[0]" value="john">
<input type="checkbox" id="mumu[1]" value="ralph">
<input type="checkbox" id="mumu[2]" value="steve">

If they are checked and submitted as POST I'll have a POST array $_POST['mumu'] which is then accesses by
$_POST['mumu'][0]
$_POST['mumu'][1]
$_POST['mumu'][2]
etc . . .

Rois
 
How can i do this "loop through" in the javascript?
 
here's an example...

Code:
var cbCollection = document.forms['YourFormName'].elements['YourCheckboxName'];

for ( var i = 0; i < cbCollection.length; i++ ) {
    if ( cbCollection[i].checked ) alert( "Checkbox " + i + " is checked!" );
}

i wouldn't use getElementById - because IDs are supposed to be unique, therefore only of of your checkboxes should have the ID you're using.



*cLFlaVA
----------------------------
[tt]somebody set up us the bomb![bomb][/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Thanks for your help Cory... you will have to excuse me for my lack of javascript skills... but I am picking it up pretty well... I hated this language for the longest time... but then i found Ajax :D ... Hey i am having trouble removing the first letter of a string.... any why this doesn't work...


Code:
datacollecting = datacollecting + "&status=" + intstatus;
var datalength = Len(datacollecting);
datacollecting = Mid(datacollecting,2,datalength-1);
 
to get the length of a string, use this:

Code:
var datalength = datacollecting.length;

to gte the "mid" of a string, use this:

Code:
datacollecting = datacollecting.substring(2);



*cLFlaVA
----------------------------
[tt]somebody set up us the bomb![bomb][/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top