Trying to do a loop in javascript

From C++ to PHP, debugging to webhosting; help and discussion about writing your latest program to running your website. NOT for help when your PC won't work.

Announcements Posted on
TSR launches Learn Together! - Our new subscription to help improve your learning 16-05-2013
Sign in to Reply
  1. georgeyboy18's Avatar
    • New Member
    • Location: oldham
    • Posts: 14
    Trying to do a loop in javascript
    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. Dez's Avatar
    • TSR Group Staff
    • The square root of rope is string.
    • Location: The South
    • Posts: 8,155
    Re: Trying to do a loop in javascript
    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. Tycho's Avatar
    • Exalted and Worshipped Member
    • Posts: 1,224
    Re: Trying to do a loop in javascript
    (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--;
    }
    }
Sign in to Reply
Share this discussion:  
Useful resources
Article updates
Moderators

We have a brilliant team of more than 60 volunteers looking after discussions on The Student Room, helping to make it a fun, safe and useful place to hang out.

Reputation gems:
The Reputation gems seen here indicate how well reputed the user is, red gem indicate negative reputation and green indicates a good rep.
Post rating score:
These scores show if a post has been positively or negatively rated by our members.