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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass checkbox array to a function

Status
Not open for further replies.

Nutthick

MIS
Jan 14, 2004
126
GB
I have a checkbox array that I need to pass to a function, but I'm having problems. My html for the array is as follows:
Code:
<input name="chkRpt[]" type="checkbox" id="rptTue" value="2" />
<input name="chkRpt[]" type="checkbox" id="rptWed" value="3" />
<input name="chkRpt[]" type="checkbox" id="rptWed" value="3" />

etc...
When the user clicks 'Go' I need to pass the array to a function. I'm using modal windows and this is the only way I can get data out. My onclick code is as follows:
Code:
onclick="sendAndClose(this.form.chkRpt)"
and my sendAndClose function is as follows:
Code:
function sendAndCloseRepeat(var1)
{
	window.dialogArguments.var1 = var1;
	window.returnValue=true;
	window.close();
}
The problem is I keep getting an error
Code:
Error: 'test.var1.0' is null or not an object
So somewhere I'm loosing my array, or maybe I didn't have it in the first place. Can anyone please tell me what I'm doing wrong?

Thanks
 
"this.form.chkRpt" is not an object - becuase you have no element nanmes "chkRpt". You have elements named "chkRpt[]" - which is an illegal name, because the [ and ] characters are invalid, and should not be used when naming elements.

I suggest renaming your elements to conform to the correct naming standard (even if it means giving all checkboxes different names), and rework the rest of your code around that.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Thanks for the help. I've taken the long way round and given each checkbox an individual name. It's not very elegant, but it works.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top