Link to home
Start Free TrialLog in
Avatar of Spartikus
Spartikus

asked on

Keypress Event

   I am new to VB Script and ASP. I am used to the Keypress event in VB and am looking for an example of the same in VB Script.
    Okay, I know there are client events for the input type=text called onkeypress and onkeydown. Can someone give me an idea how these events are properly taken advantage of?
    Please post your code below. (I am specifically looking for a way to check for the enter key to direct the page to a sub, and not allowing for ' character in certain fields for obvious reasons.)

Thanks in advance.
Avatar of cable4096
cable4096


<script language="VBScript">
Sub cmd_Status_Click_Keypress
if KeyASCII = 13 then
   Navigate "subpage.asp"
End if
End Sub
</script>

The button named cmd_Status will have a Keypress event. ASCII 13 is a carriage return, if the user presses this on the button, it will go to subpage.asp via the navigate command.

I suppose you could have it on a Form event as well?

As for not allowing the ' character, just do a:

s_text = Replace(s_text,"'","")

Before submitting a string via the navigate command.
Sorry, I think it should be without the click in the name of the sub. Try the replace command like this:

<script language="VBScript">
Sub cmd_Status_Keypress
Dim s_Text
if KeyASCII = 13 then
   s_Text = "" & document.form.txtname.value
   s_Text = Replace(s_Text,"'","")
   Navigate "subpage.asp?s_Text=" & s_Text
End if
End Sub
</script>

It combines the technuiqes, removing the quote characters from the string, and then navigating to the sub page with a parameter set to the text box the user entered information into.

Some people doublequote like so:
s_Text = Replace(s_Text,"'","''")

Or chnage it to the aposterphy

s_Text = Replace(s_Text,"'","`")

Avatar of Spartikus

ASKER

Edited text of question.
cable4096

   -Did you test this answer? It doesn't appear as it really recognizes KEYAscii in the sub...  please explain to me why when I try it, it does not.
cable4096

   -Did you test this answer? It doesn't appear as if it really recognizes KEYAscii in the sub...  please explain to me why when I try it, it does not.
ASKER CERTIFIED SOLUTION
Avatar of markdouglas
markdouglas

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
   This is a good answer though it isn't in VB Script. As it turns out I managed to develop a solution before receiving this answer.

The key to the solution for me was IE 4 recognizes onkeydown. Then it was a matter of using window.event.keyCode to check for whichever key was pressed.

Thanks for the help.