Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


form.elements[i] in MSIE

Posted on 1997-04-29
Medium Priority
Last Modified: 2012-06-21

  Hiya.  The following snippet of code validates the
  quantity fields on an order form.
  I don't know how many fields may be on this page,
  so I'm using a while loop rather than a for loop
  to loop through the form elements.
  This is fine using Netscape.  Elements that do not
  exist return a null.
  Using MSIE 3.0, however, I get a jscript error.
  (Scripting error: Unknown name.)
  Can anyone suggest a method of looping through an
  unknown number of form elements (specifically
  text fields) that works in MSIE?
  James Honaker
  // validates form data
  function Validate(form) {
    var i=0;
    while (form.elements[i]) {
      if (form.elements[i].name=="quantity") {
        var element=form.elements[i];
        var name=element.name;
        var value=element.value;
        if (IsEmpty(value) || !IsPosInteger(value)){
          var msg="Please enter a quantity from 0 to 999.\n\n";
          msg+="Enter 0 to remove this item from your order.";
          return false;
    return true;
Question by:jhonaker
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment

Accepted Solution

RM032397 earned 50 total points
ID: 1265348
Base the 'for' loop test on


Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question