Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9291415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T20:38:27+00:00 2026-06-18T20:38:27+00:00

Why the for loop does not run? The Error-Console is empty The function countfiles

  • 0

Why the for loop does not run?

  • The Error-Console is empty
  • The function countfiles return a whole number
  • parseInt(countfiles()) also not work too

Here my Code:

function set_default_value() {
    var element = document.getElementsByName('fields');
    for (var i = countfields(); i < element.length; ++i) {
        element[i].value = "default";
    }
}

Why does not run?

EDIT:

  • Countfields is lower than element.length
  • The function is running
  • Countfield return a number like 0, 1, 2, 3, …

Here’s the function countfields

function countfields() {
    var field_counter = 0;
    for (var i = 0; i < 50; i++) {
        if (typeof document.getElementsByName('other_fields')[i] != "undefined") {
        var field_counter = field_counter + 1; 
        }
    }
    return field_counter; 
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T20:38:28+00:00Added an answer on June 18, 2026 at 8:38 pm

    @varunachar touched on the issue in one of his comments:

    The number returned by countfields could be greater than element.length

    In this line:

    for (var i = countfields(); i < element.length; ++i)
    

    Read this i < element.length as “as long as i is less than element.length, do stuff”. Or, if countfields() is equal or greater, nothing happens.

    1 other_fields: http://jsfiddle.net/D5ZHV/ works
    6 other_fields: http://jsfiddle.net/Ay6BN/ does not work

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to increment the value of i . The for loop does not
hey does anyone know how to loop through the MedRV function in the RTAQ
Does it run in a loop polling the contents? (Highly unlikely and inefficient.) Or
Does defining functions inside a loop affect performance? Like var doSomething = function(element){ $(element).whatever();
The following does not compile: int result = Math.random() + 1; error: possible loss
java.lang.IllegalArgumentException: column 'data3' does not exist whats with data3 column?? LogCat 03-24 07:05:36.091: ERROR/AndroidRuntime(2540):
because obj, the playingCard object is created inside a nested for loop does that
When does it make sense to use Loop fission/distribution if I am compiling for
Does a java for-each loop guarantee that the elements will be presented in order
What does the second line inside this for loop means and what will be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.