Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    May 2004
    Location
    The First State
    Posts
    233
    Thanks
    9
    Thanked 0 Times in 0 Posts

    looping thru checkbox help

    I have a group of checkboxes that passes data to another page:

    Code:
    <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:

    Code:
    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?

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    where is the condition to check for the other regex?
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

  • #3
    Regular Coder
    Join Date
    May 2004
    Location
    The First State
    Posts
    233
    Thanks
    9
    Thanked 0 Times in 0 Posts
    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:
    Code:
    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?

  • #4
    Regular Coder
    Join Date
    May 2004
    Location
    The First State
    Posts
    233
    Thanks
    9
    Thanked 0 Times in 0 Posts
    figured it out:

    Code:
    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?

  • #5
    Regular Coder
    Join Date
    May 2004
    Location
    The First State
    Posts
    233
    Thanks
    9
    Thanked 0 Times in 0 Posts
    thanks for the help


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •