Solved

Need Javascript to work in Firefox

Posted on 2007-04-02
5
394 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

729 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