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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need Help on Client Side VBScript

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Anybody knows how to write client side vbscript? I need to check if the required fields are filled when the submit button of a HTML form is clicked. Lets say the name of the submit button is btnSubmit. I wrote something like this:

Sub btnSubmit_onClick()
If Len(field1.value) = 0 then
alert "Please fill in field1"
form.field1.focus
ElseIf Len(field2.value) = 0 Then
alert "Please fill in field2"
form.field2.focus
......
End If
End Sub

When I click the submit button, an alert box pops up for the first missing field. But after I click OK, it submits the form to the server instead of setting focus back on the missing field.

Any help is appreciated.

 
Dunno whether it will work but try putting a RETURN after each of your form.fieldx.focus[/red] this will return you to the page you are on not send you forward to the next one.

i.e.
Sub btnSubmit_onClick()
If Len(field1.value) = 0 then
alert "Please fill in field1"
form.field1.focus
return
ElseIf Len(field2.value) = 0 Then
alert "Please fill in field2"
form.field2.focus
return
......
End If
End Sub



Try it let me know. DeltaFlyer ;-)

DeltaFlyer - The Only Programmer To Crash With Style.
 
DeltaFlyer,

It doesn't work with "return". Neither does "exit sub". I think I have to use javascript. Anyway, thank you very very much.

sadow
 
I don't know if this works, but try to change your sub into a function and return true (1) or false (0) depending on success or failure.

Code:
function btnSubmit_onClick()
   ...
      btnSubmit = false
      exit function
   ...
end function

This is about the same as JavaScript. Most of the time, however, using JavaScript on the client is a better solution, because your page will not work in NetScape for example, as client-side VBScript is proprietary to Internet Explorer.
Yours,

Rob.
 
Rob,

It's not working with VBScript function. I wrote a JavaScript function and it works fine. Thanks a lot.

Shadow
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top