Solved

Need Javascript to work in Firefox

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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…

746 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now