Results are out! Find what you need...fast. Get quick advice or join the chat
Hey there Sign in to join this conversationNew here? Join for free

Trying to do a loop in javascript

Announcements Posted on
Applying to Uni? Let Universities come to you. Click here to get your perfect place 20-10-2014
    • Thread Starter
    • 0 followers
    Offline

    ReputationRep:
    I have 5 editable fields for an app, but to execute the code i need to do a check to see if all 5 are filled, if 4 are filled different code to execute is needed

    So anyone know how i can do a loop for a check field 5 = null
    loop back to field 4 and check field 4 = to null (if not equal to 4 run code)
    • 38 followers
    Offline

    ReputationRep:
    I'm not quite sure what logic you're after, your post is a bit confusing TBH. It sounds like you'd be better off using an if/else statement, or a switch, rather than a loop. :erm:
    • 0 followers
    Offline

    ReputationRep:
    (Original post by georgeyboy18)
    ...if 4 are filled different code to execute is needed...
    I hope this is for practical purposes rather than because your execution code can't handle checking to determine the quantity of inputs?

    In any case an if/else would work, but a loop can also work. You'd want to have your inputs labelled with a numerical identifier descending from 5. Something like:

    Code:
    $x=5;
    while ($x>0) {
    if (value-in-input$x != "") {
    // Forward to this $handler[$x]
    } else {
    $x--;
    }
    }

Reply

Submit reply

Register

Thanks for posting! You just need to create an account in order to submit the post
  1. this can't be left blank
    that username has been taken, please choose another Forgotten your password?
  2. this can't be left blank
    this email is already registered. Forgotten your password?
  3. this can't be left blank

    6 characters or longer with both numbers and letters is safer

  4. this can't be left empty
    your full birthday is required
  1. By joining you agree to our Ts and Cs, privacy policy and site rules

  2. Slide to join now Processing…

Updated: June 15, 2012
New on TSR

What is sixth form like?

Share your story!

Article updates
Useful resources
Reputation gems:
You get these gems as you gain rep from other members for making good contributions and giving helpful advice.