form validation

Results 1 to 3 of 3

Thread: form validation

  1. #1
    dummy Guest

    Default form validation

    lets say i have following code in asp:<BR><BR>&#060;form action=update.asp action=post name=frmuser&#062;<BR> Please enter Name to add: <BR><BR><BR>&#060;% dim na<BR> na = 10<BR> <BR> for i=1 to na %&#062;<BR> &#060;Input type=text name="user&#060;%=i%&#062;" &#062;<BR> <BR><BR> &#060;% next %&#062;<BR><BR>&#060;INPUT TYPE="submit" NAME="submit" VALUE="Submit" <BR><BR>onclick="javascript:return(inputvalidate() )"&#062;<BR>&#060;INPUT TYPE="reset" NAME="reset" VALUE="Reset"&#062;<BR>&#060;/FORM&#062;<BR><BR>How do i check whether user has entered name in the textbox field? If user has not key in any value and submit, an alert message will pop up to request user enter at least one name.. etc?<BR>I don&#039;t know how to code in javascript validation coz it is an array "user[]", anyone know please help me? thank you.<BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: form validation

    Something like:<BR><BR>foundName = false;<BR>users = document.FormName.user;<BR>for ( i = 0; i &#060; users.length; ++i )<BR>{<BR>&nbsp; &nbsp; if ( users[i].value &#060;&#062; "" ) <BR>&nbsp; &nbsp; {<BR>&nbsp; &nbsp; &nbsp; &nbsp; foundName = true;<BR>&nbsp; &nbsp; }<BR>}<BR><BR>...<BR><BR>I should point out that just checking to see if the value of the field is not "" is really a mistake, because if the user enters just a single space character, then " " is *not* equal to "".<BR><BR>So you really need to "trim" the values first. But the above should get you started.<BR><BR>

  3. #3
    Join Date
    Dec 1969


    I didn&#039;t notice that you were giving each &#060;INPUT&#062; field a different name! You said the user was an array, and I believed you. No, it is *NOT* an array!<BR><BR>All you need to do is:<BR><BR>foundName = false;<BR>for( i = 1; i &#060;= na; ++i )<BR>{<BR>&nbsp; &nbsp; if ( document.TheForm.elements["user"+i].value &#060;&#062; "" Then foundName = true;<BR>}<BR><BR>Even easier. The only array involved now is the standard "elements" array of the form!<BR><BR>

Posting Permissions

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