Results are out! Find what you 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
  1. Offline

    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)
  2. Offline

    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:
  3. Offline

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

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


Submit reply


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
2015 general election
New on TSR

Win a postgrad place

Scholarship worth over £9,000 up for grabs

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