Solved

Need Javascript to work in Firefox

Posted on 2007-04-02
5
375 Views
Last Modified: 2011-10-03
My javascript works fine in ie 6, but I get nothing in firefox.

From an asp page...   <asp:textbox id="Quantity" runat="server" Width="72px" onKeyDown="handleKeyPress();"></asp:textbox>

Someone elses answer -- (didn't work when I added to javascript)
By specifying runat="server", you've told the system to handle the actions at the server side, not the client side.  You can easily specify a local operation by setting an attribute in your ASP.NET code, like this:

void Page_Load(object sender, EventArgs e) {
      Quantity.Attributes.Add("onkeydown",
           "javascript:handleKeyPress();");
   }
0
Comment
Question by:sl1nger
  • 2
  • 2
5 Comments
 
LVL 17

Expert Comment

by:gops1
ID: 18838298
Show your handleKeyPress() function
0
 

Author Comment

by:sl1nger
ID: 18839077
           function handleKeyPress(evt) {
                        var nbr;
                        if (window.Event) nbr = evt.which;
                        else nbr = event.keyCode;
                        if(nbr==13){
                              document.frmLT.btnSubmit.focus();
                        }
                  }
0
 
LVL 19

Accepted Solution

by:
dakyd earned 300 total points
ID: 18839668
Looks like you've got the event stuff backwards, and you used a capital "E" for event.  window.event only exists in IE browsers (notice the lower case), and you normally pass in the event, evt, for all other browsers.  Since you had a typo, though, the first part of the if case always fails, so all browsers end up using event.keyCode.  Give this a shot:

function handleKeyPress(evt)
{
  var nbr;
  if (window.event)
    nbr = event.keyCode;
  else
    nbr = evt.which;
  if(nbr == 13)
    document.frmLT.btnSubmit.focus();
}

Hope that helps.
0
 
LVL 17

Assisted Solution

by:gops1
gops1 earned 200 total points
ID: 18840932
Another point slinger, do not forget to pass event if you want this to work in firefox.

onKeyDown="handleKeyPress(event);"
0
 

Author Comment

by:sl1nger
ID: 18846520
Works great!!  Thx a bunch...
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

821 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