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
Solved

Need Javascript to work in Firefox

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

837 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