Validating a form

Results 1 to 3 of 3

Thread: Validating a form

  1. #1
    Marc Polson Guest

    Default Validating a form

    I have an HTML page containing a form with approx 70 items shown and a text box next to each. The user places the number of each item they wish to be added in the text box ( Default is 0 ). Now the problem is due to the databas setup, the total amount of all the items cannot exceed 30. My question is, how would i validate the form client side so that the total amount of the items does not exceed 30?<BR><BR>Any help would be much appreciated

  2. #2
    Join Date
    Dec 1969

    Default RE: Validating a form

    Hi!<BR><BR>Write a function that you will call with onSubit().<BR>The function should loop through all the indexes of your<BR>forms elements-array, checking where the current values differs from your default which is 0. If this is evaluates to true add 1 to an fieldsCounter variabel.<BR><BR>When the loop is finished check the value of fieldsCounter to see if it is greater then 30, if so return false. This will stop the form from being sent.Else return true and the form will fly into the great wide open.<BR><BR>function checkForm()<BR>{<BR> var i = 0;<BR> var fieldsCounter = 0;<BR> while(i &#060; document.yourForm.Length)<BR> {<BR> if(fieldsCounter &#062; 30){break;}<BR> else<BR> { <BR> if(document.yourForm.elements[i].value != 0)<BR> {fieldsCounter++;}<BR> i++;<BR> }<BR> }<BR><BR> if(fieldsCounter &#062; 30)<BR> {<BR> fieldsCounter = 0;<BR> return false;<BR> }<BR> else<BR> {<BR> return true;<BR> }<BR>}<BR><BR>Havent tried the code above but it should work,<BR><BR>Best regards<BR>Lars

  3. #3
    TekTronix Guest

    Default RE: Validating a form

    First, determine the recordcount of the current recordset (rst.recordcount). If the counter exceeds 30, place a javascript that displays a messagebox upon submission with a message &#039cannot add new record&#039. If the counter &#060; 30 then use a normal form-validating javascript.

Posting Permissions

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