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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Using counter as part of form names

    I have 2 questons.


    1) Is there a way for the loop counter to loop while less then [a php variable]?
    2) Is there a way to use a counter in the name of the form elements? Example, instead of "switchBox1" use: "switchBoxCounter"
    instead of "nameaddy1" use: "nameaddyCounter"
    Code:
    if(document.form1.switchBox1.checked)
      {
        document.form1.nameaddy1.style.backgroundColor = "#E5E5E5";
      }
     else
      {
        document.form1.nameaddy1.style.backgroundColor = "#FFFFFF";
      }

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,922
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    1)
    Code:
    while (x < 10) {
    or for (i = 10, i>=0; i--) {
    2) Use square bracket notation.

    Code:
    if (document["form1"]["switchBox"+counter].checked) {
    NEW! FREE DELIVERY when you collect from store. - Debenhams' advertisement


  •  

    Posting Permissions

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