Solved

Need Javascript to work in Firefox

Posted on 2007-04-02
5
390 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

734 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