From: acidrainlte on
Hi,

I would like to add an onkey press as an alternative to the Ok button in
this code. How would I go about doing this (I'm fairly new to VBS)?

<SCRIPT LANGUAGE="VBScript">

Sub RunScript
OKClicked.Value = "OK"
End Sub

Sub CancelScript
OKClicked.Value = "Cancelled"
End Sub

</SCRIPT>

<BODY>
<font size="2" face="Arial">
Username: </font><font face="Arial">
<input type="username" name="UserName" size="40"></font></p>

<font size="2" face="Arial">
Password: </font><font face="Arial">
<input type="password" name="UserPassword" size="40"></font></p>

<input type="hidden" name="OKClicked" size = "20">

<input id=runbutton class="button" type="button" value=" OK "
name="ok_button" onClick="RunScript">

<input id=runbutton class="button" type="button" value="Cancel"
name="cancel_button" onClick="CancelScript">

</BODY>

Thanks in advance.
From: mayayana on
Sub Document_onkeypress()
If window.event.srcElement.ID = "runbutton" then
'-- There was a keypress while button was selected.
End If
End Sub

The srcElement child object of the event object
represents the element involved in the event. You
can access any properties or methods that element
has normally.

>
> I would like to add an onkey press as an alternative to the Ok button in
> this code. How would I go about doing this (I'm fairly new to VBS)?
>
> <SCRIPT LANGUAGE="VBScript">
>
> Sub RunScript
> OKClicked.Value = "OK"
> End Sub
>
> Sub CancelScript
> OKClicked.Value = "Cancelled"
> End Sub
>
> </SCRIPT>
>
> <BODY>
> <font size="2" face="Arial">
> Username: </font><font face="Arial">
> <input type="username" name="UserName" size="40"></font></p>
>
> <font size="2" face="Arial">
> Password: </font><font face="Arial">
> <input type="password" name="UserPassword" size="40"></font></p>
>
> <input type="hidden" name="OKClicked" size = "20">
>
> <input id=runbutton class="button" type="button" value=" OK "
> name="ok_button" onClick="RunScript">
>
> <input id=runbutton class="button" type="button" value="Cancel"
> name="cancel_button" onClick="CancelScript">
>
> </BODY>
>
> Thanks in advance.


From: LikeToCode on
You would put what code is to be executed for each button click.

<SCRIPT LANGUAGE="VBScript">

Sub RunScript
'call your run code here.
If username.value <> "" Then
MsgBox username.value
Else
MsgBox "Username field is empty."
End If

End Sub

Sub CancelScript
'call your cancel code here.
me.close()
End Sub

</SCRIPT>