...

View Full Version : looping thru checkbox help



finstah1
08-12-2008, 05:08 PM
I have a group of checkboxes that passes data to another page:



<input type="checkbox" name="wcsave_b06_Relation" value="Current UD Student" /> Current UD Student, Expected graduation: <input type="text" name="wcsave_Relation00" value="" size="10" maxlength="25" /><br />

<input type="checkbox" name="wcsave_b07_Relation" value="Undergraduate Alumnus/a" /> Undergraduate Alumnus/a<br />

<input type="checkbox" name="wcsave_b08_Relation" value="Graduate Alumnus/a" /> Graduate Alumnus/a<br />

<input type="checkbox" name="wcsave_b09_Relation" value="Spouse of Alumnus/a" /> Spouse of Alumnus/a<br />

<input type="checkbox" name="wcsave_b10_Relation" value="Friend" /> Friend<br />

<input type="checkbox" name="wcsave_b11_Relation" value="Faculty/Staff" /> Faculty/Staff<br />

<input type="checkbox" name="wcsave_b12_Relation" value="Retired Faculty/Staff" /> Retired Faculty/Staff<br />

<input type="checkbox" name="wcsave_b13_Relation" value="Parent" /> Parent, Parent of: <input type="text" name="wcsave_Relation01" value="" size="20" maxlength="150" /> Expected graduation: <input type="text" name="wcsave_Relation02" value="" size="10" maxlength="25" /><br />

<input type="checkbox" name="wcsave_b16_Relation" value="Trustee" /> Trustee<br />

<input type="checkbox" name="wcsave_b17_Relation" value="Past Trustee" onblur="CheckField(this.form,this,'');" /> Past Trustee<br />

<input type="checkbox" name="wcsave_b18_Relation" value="Other" /> Other, specify: <input type="text" name="wcsave_b19_Relation" value="" size="35" maxlength="100" />



on the next page I am running through a loop so that it displays only what is checked:



var relation = /^wcsave_b/;
var other = /^wcsave_Relation/;
var ips=document.getElementsByTagName("input");
for (var x=0; x < ips.length; x++){
var nm = ips[x].name
if(relation.test(nm) && ips[x].value !=0){
document.write("<style='line-height: 8px;'>" + ips[x].value + "<br />");
}
}


but I can only get the "relation" to display and not "other". I tried adding it to the test section. i.e. other.test(nm)... but then nothing displays.

My question is, how do I display the appropriate text boxes that are associated with the checked fields?

shyam
08-13-2008, 06:42 AM
where is the condition to check for the other regex?

finstah1
08-13-2008, 02:38 PM
that's what I was unsure of.

I wanted to add other.test(nm) but it wouldn't work. I wanted to know how I can do 2 conditions in my code above. Works great for one, but how to include 2?

I had:


var relation = /^wcsave_b/;
var other = /^wcsave_Relation/;
var ips=document.getElementsByTagName("input");
for (var x=0; x < ips.length; x++){
var nm = ips[x].name
if(relation.test(nm) && other.test(nm) && ips[x].value !=0){
document.write("<style='line-height: 8px;'>" + ips[x].value + "<br />");
}
}


Is there a way to use .test for more than 1 item?

finstah1
08-13-2008, 04:56 PM
figured it out:



var relation = /^wcsave_b/;
var ips=document.getElementsByTagName("input");
for (var x=0; x < ips.length; x++){
var nm = ips[x].name
if(relation.test(nm) && ips[x].value !=0) {
document.write("<span style='line-height: 8px;'>" + ips[x].value);
if (nm == "wcsave_b06_Relation") {
document.write(", Expected graduation: " + document.getElementsByName("wcsave_Relation00")[0].value );
}
else if (nm == "wcsave_b13_Relation") {
document.write(" Parent of: " + document.getElementsByName("wcsave_Relation01")[0].value + " Expected graduation: " + document.getElementsByName("wcsave_Relation02")[0].value );
}
document.write("</span><br />");
}
}



but the doc.write's are ugly. :(

I had it printing to a div via innerHTML but it was displaying twice. Any ideas why?

finstah1
08-14-2008, 01:52 PM
thanks for the help :(



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum