Solved

form.elements[i] in MSIE

Posted on 1997-04-29
1
258 Views
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?
 
  TIA,
  James Honaker
  jhonaker@spaceworks.com
 
  //
  // 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.";
          alert(msg);
          element.select();
          element.focus();
          return false;
        }
      }
      i++;
    }
    return true;
  }
 
0
Comment
Question by:jhonaker
1 Comment
 
LVL 3

Accepted Solution

by:
RM032397 earned 25 total points
ID: 1265348
Base the 'for' loop test on
form.elements.length


0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

808 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