We help IT Professionals succeed at work.

vb script text field validation

woollar1
woollar1 asked
on
hi guru's

with vbscript how do you clear textboxes and setfocus and then call functions in separate vbscript to validate the text before it is sent to the server when the submit button is clicked ??

woollar

Comment
Watch Question

Commented:
You usually perform client side validations (and other client side special effects) using JavaScript. If you know your DOM, VBScript works fine with nearly the same syntax. VBScript works in IE only.
THIS IS SAMPLE....


<HTML>
<HEAD>
<SCRIPT ID=clientEventHandlersVBS LANGUAGE=vbscript>
<!--
Sub button1_onclick
IF FORM1.text1.value="" THEN
     MSGBOX "ENTER TEXT"
     FORM1.text1.focus
END IF
End Sub
-->
</SCRIPT>
</HEAD>
<BODY>
<FORM id=FORM1 name=FORM1 action="" method=post>
<P>&nbsp;</P>
<P><INPUT id=text1 name=text1></P>
<P><INPUT id=text2 name=text2></P>
<P><INPUT id=button1 type=button value=Button name=button1 ></P></FORM>
</BODY>
</HTML>

Good Luck...:)

Author

Commented:
thanks ravi for your help
could i just ask you how i can put the vb script in a separate file from the main script and include it so it still gets called when the user clicks on the submit button?

thanks woollar1
Yes. You can do so.

here is the same sample...

sct.vbs
========
Sub button1_onclick
IF FORM1.text1.value="" THEN
    MSGBOX "ENTER TEXT"
    FORM1.text1.focus
END IF
End Sub


page.htm
========
<HTML>
<HEAD>
<script language="vbscript" src="sct.vbs"></script>
</HEAD>
<BODY>
<FORM id=FORM1 name=FORM1 action="" method=post>
<P>&nbsp;</P>
<P><INPUT id=text1 name=text1></P>
<P><INPUT id=text2 name=text2></P>
<P><INPUT id=button1 type=button value=Button name=button1 ></P></FORM>
</BODY>
</HTML>

Good Luck...:)

Author

Commented:
sorry about the delay ravi, thanks for your help

woollar.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.