Solved

Keypress Event

Posted on 2000-04-18
7
448 Views
Last Modified: 2008-02-20
   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.
0
Comment
Question by:Spartikus
  • 4
  • 2
7 Comments
 
LVL 1

Expert Comment

by:cable4096
ID: 2728081

<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.
0
 
LVL 1

Expert Comment

by:cable4096
ID: 2728103
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,"'","`")

0
 
LVL 1

Author Comment

by:Spartikus
ID: 2728466
Edited text of question.
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 1

Author Comment

by:Spartikus
ID: 2728527
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.
0
 
LVL 1

Author Comment

by:Spartikus
ID: 2728531
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.
0
 

Accepted Solution

by:
markdouglas earned 100 total points
ID: 2730987

I use this Javascript Client Side code quite often to detect the enter key or the escape key on a page.  



This is the html required
<html>
<body  onkeypress="CmdKeyPress();" onload="OnWindowLoad();" >
</html>




This is the Client side code required
<script language="JavaScript">

function CmdKeyPress()
{
      var strKeyCode;

      strKeyCode = window.event.keyCode;
        // Enter
      if(strKeyCode == 13)
      {
            if(document.YourForm.cmdSave.disabled == false)
            {   // Call Function1
                  Function1();
            }
            else
            {    // Call Function2
                  Function2();
            }
      }
        // Cancel
      if(strKeyCode == 27)
      {
            Function3();
      }
}

</Script>

0
 
LVL 1

Author Comment

by:Spartikus
ID: 2731527
   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.
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question