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 7 of 7
  1. #1
    Regular Coder
    Join Date
    May 2004
    Location
    The First State
    Posts
    233
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Question printing check box values using substring() HELP!!!

    Hi all,

    I'm passing checkbox values between pages and have them collected (with submitted data) in hidden fields at the top of my form on page 2.

    Code:
    <input name="wcsave_b00_janfeb" type="hidden" value="January 3-February 25">
    <input name="wcsave_b01_febapr" type="hidden">
    <input name="wcsave_b02_mayjun" type="hidden" value="May 2-June 24">
    When I try to write the values farther down in the page, they don't appear.

    I'm trying to use the indexOf with the substring function that says loop thorugh every form field that starting with the name wcsave_b that has a value associated with it above, print out below. Here's the javascript I have:

    Code:
    var checkString = "wcsave_b"
    		
    checkString.substring(0, checkString.indexOf(" "))
    						
    for (var i=1; i < document.forms[0].elements[i].length; i++)
    {
    								if(document.forms[0].elements.name[i] == "wcsave_b")
    {
    boxes = document.forms[0].elements[i].value.
    										    document.write(boxes);
      }
    }
    How come the values don't print below?


  • #2
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well, your entire script appears to be out of whack... try taking it one step at a time (hint: the alert() method is handy).
    *this message will self destruct in n-seconds*

  • #3
    Regular Coder
    Join Date
    May 2004
    Location
    The First State
    Posts
    233
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Here is the code watered down. It just checks to see if the checkbox with the value of wcsave_b0_janfeb is had a value passed and if it did, print it out

    Code:
    for (var i=1; i < document.forms[0].elements.length; i++)
      {								     if(document.forms[0].elements[i].name == "wcsave_b00_janfeb")
      {										document.write(document.forms[0].elements[i].value)
      }
    }
    this works great but I am unclear on what I need to do with the substring function to see that fields with (0,8) == wcsave_b0 then print out the value.

  • #4
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have no idea of what you're asking.
    *this message will self destruct in n-seconds*

  • #5
    Regular Coder
    Join Date
    May 2004
    Location
    The First State
    Posts
    233
    Thanks
    9
    Thanked 0 Times in 0 Posts
    I'm looping thru all of my form fields.

    for (var i=0; i < document.forms[0].elements.length; i++)
    {


    The names I'm interested in are: wcsave_b01_janfeb, wcsave_b02_aprjun, wcsave_b03_sept_oct and so on. Since all of the names have wcsave_b in common, I want to say if any of those form field names if(document.forms[0].elements[i].name contain the string "wcsave_b"

    then print out the value associated with the fields containing the string "wcsave_b".

    document.write(document.forms[0].elements[i].value + "<br>")

  • #6
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    In that case, a regular expression would be simpler:
    Code:
    var rx = /^wcsave_b/;
    // loop...
    
    if(rx.test(document.forms[0].elements[i].name))
    	// do it...
    *this message will self destruct in n-seconds*

  • #7
    Regular Coder
    Join Date
    May 2004
    Location
    The First State
    Posts
    233
    Thanks
    9
    Thanked 0 Times in 0 Posts
    beautiful. Thank you!!!!


  •  

    Posting Permissions

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