form collection

Results 1 to 6 of 6

Thread: form collection

  1. #1
    b.charter Guest

    Default form collection

    how do u loop through all the input boxes on a form in javascript. what is the collection name; does it have a count method and item method?

  2. #2
    Join Date
    Dec 1969

    Default You mean *in* the browser?

    In JS code in the browser?<BR><BR>for ( var elnum = 0; elnum &#060; document.FormName.elements.length; ++elnum )<BR>{<BR>&nbsp; &nbsp; oneElement = document.FormName.elements[ elnum ];<BR>&nbsp; &nbsp; ...<BR>}<BR><BR>

  3. #3
    b.charter Guest

    Default RE: You mean *in* the browser?

    thanks, but one *last* question, since u always seem to know the answer. i have a function and i want to apply it in the for loop; it returns true or false if the field is blank; the only problem is that when it returns false, the alert box pops up and it recognizes it as false, but it still submits the form... i know its something miniscule, but i can&#039;t figure it out.

  4. #4
    Join Date
    Dec 1969

    Default Hard to guess...

    ...when you don&#039;t show your code.<BR><BR>I will *guess* you have something like this:<BR><BR>function validateTextBox( box )<BR>{<BR>&nbsp; &nbsp; if ( box.value.length == 0 )<BR>&nbsp; &nbsp; {<BR>&nbsp; &nbsp; &nbsp; &nbsp; alert("You didn&#039;t type anything in textbox " +;<BR>&nbsp; &nbsp; &nbsp; &nbsp; return false;<BR>&nbsp; &nbsp; }<BR>&nbsp; &nbsp; return true;<BR>}<BR><BR><BR>function validate( )<BR>{<BR>&nbsp; &nbsp; for ( ... looking at all form elements ... )<BR>&nbsp; &nbsp; {<BR>&nbsp; &nbsp; &nbsp; &nbsp; oneElement = ...<BR>&nbsp; &nbsp; &nbsp; &nbsp; ... test one element for valid value ...<BR>&nbsp; &nbsp; &nbsp; &nbsp; ... assume that you test different types differently ...<BR>&nbsp; &nbsp; &nbsp; &nbsp; if ( oneElement.type = "text" ) // may not be right string!<BR>&nbsp; &nbsp; &nbsp; &nbsp; {<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ( ! validateTextBox( oneElement ) ) return false;<BR>&nbsp; &nbsp; &nbsp; &nbsp; }<BR>&nbsp; &nbsp; }<BR>&nbsp; &nbsp; return true;<BR>}<BR><BR>And then in the form:<BR><BR>&#060;FORM Name=... onSubmit="return validate();" ... &#062;<BR><BR>If you forget the "return" in the onSubmit, that would do what you are saying.<BR><BR>If you don&#039;t return false *from the main validation code*, that would do it.<BR><BR>It&#039;s not enough for a specific validation (e.g., of a text field) to return false. That return must be detected in the main validation and false returned from there, too. And the return has to be in the onSubmit.<BR><BR>But show your code if it&#039;s a lot different than that.<BR><BR>

  5. #5
    b.charter Guest

    Default RE: Hard to guess...

    bill; two books and one c++ class later, your still the most reliable source for information. touche!

  6. #6
    Darren Neimke Guest

    Default Also, take a look at this..

    This is a more elaborate version of that which Bill showed you.<BR><BR><BR><BR><BR>HTH<B R>Darren

Posting Permissions

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