Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VbScript form Validation with an array 1

Status
Not open for further replies.

WorkSuxs

Programmer
Jan 26, 2005
28
US
This has been bugging me for some time now. I get a (dynamic) list of a product name and description from a database that is loaded into arrays. I then display the product name and allow the users to edit the descriptions. I loop thought the arrays and use the following for the description: <input name="productDescription(<%=h%>)" size=50 maxlength=75 value="<%=productDescription(h)%>">

The issue is I want to validate that there is a description when they click the submit button. I have tried this and it does not work.

Function UpdateProductDescription_onSubmit()
Dim h, errorFound
For h = 1 to document.UpdateProductDescription.nbrofrecords.value
If Len(Trim(document.UpdateProductDescription.productDescription(h).value)) = 0 Then
str = alert("Product Description is Required")
errorFound = “True”
Exit For
End If
Next
If errorFound = “True” Then
UpdateProductDescription_onSubmit = False
Else
document.UpdateProductDescription.action = "test.asp"
UpdateProductDescription_onSubmit = True
End If
End Function
 
Unless you somehow KNOW that a page will only ever be used with Internet Explorer then clien-side script should be done in JavaScript.
 
> If Len(Trim(document.UpdateProductDescription.productDescription(h).value)) = 0 Then
[tt] If Len(Trim(document.UpdateProductDescription.[red]elements("[/red]productDescription[red]"+h[/red]).value)) = 0 Then[/tt]

>UpdateProductDescription_onSubmit = False
[tt]window.event.returnValue = False[/tt]

>UpdateProductDescription_onSubmit = True
[tt]window.event.returnValue = True[/tt]
 
Thanks tsuji, that worked!

Sheco, I'm in a large company and the standard is for MS IE only. I should have posted that with the original question.
 
I'm in a large company and the standard is for MS IE only

let's hope no one decides to change that policy in the future...

Or that you ever need to open up these web applications to a partner - e.g. a customer or vendor or outsource partner who has a different view of the world when it comes to standards compliant tools.

Or use it on a device that doesn't support IE.

Or want to demonstrate to future employers how well you understand web design and development standards and cross platform solution development.



A smile is worth a thousand kind words. So smile, it's easy! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top