www.webdeveloper.com
Results 1 to 3 of 3

Thread: for loop in checkboxes js

  1. #1
    Join Date
    Feb 2013
    Posts
    2

    Post for loop in checkboxes js

    Hello, How I can write the following code in a for loop?


    if (theF.red.checked) {

    cost += parseFloat(theF.red.value);

    }

    if (theF.yellow.checked) {

    cost += parseFloat(theF.yellow.value);

    }

    if (theF.blue.checked) {

    cost += parseFloat(theF.blue.value);

    }

  2. #2
    Join Date
    Aug 2008
    Location
    Sweden
    Posts
    227
    Code:
    var colors = ['red', 'yellow', 'blue'];
    for (var i = 0; i < colors.length; i++) {
        if (theF[colors[i]].checked)
            cost += parseFloat(theF[colors[i]].value);
    }
    
    New to web development or in need of a good reference? Check out the Mozilla Developer Network or W3Schools.

  3. #3
    Join Date
    Feb 2013
    Posts
    2

    Question

    thanks a lot for the help.. but if I have to process unknown number of elements ?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles