problem with defaultbutton cross browser

P

PNR

I have a problem making a deafultbutton that works cross browser, I tried
setting a defaultbutton on a panel, but that diden't work in Firefox. I have
also tried to use som java-script:
I have added a "onkeydown" event to the textbox that shall belon to a
certain button

<script type="text/javascript" language="JavaScript1.2">

function defaultButtonFunktion(evt, btn) {
var keyCode = evt.which ? evt.which : evt.keyCode;
if (keyCode == 13) {
evt.returnValue=false;
evt.cancel = true;
btn.click();
}
}
</script>

This also dossen't work in FireFox.

What do I do?

Thanks in adavance
 
G

Guest

I have a problem making a deafultbutton that works cross browser, I tried
setting a defaultbutton on a panel, but that diden't work in Firefox. I have
also tried to use som java-script:
I have added a "onkeydown" event to the textbox that shall belon to a
certain button

<script type="text/javascript" language="JavaScript1.2">

        function defaultButtonFunktion(evt, btn) {
            var keyCode = evt.which ? evt.which : evt.keyCode;
            if (keyCode == 13) {
                evt.returnValue=false;
                evt.cancel = true;
                btn.click();
            }
        }
    </script>  

This also dossen't work in FireFox.

What do I do?

Thanks in adavance

Looks like your code is correct. At least, for me it works in IE and
FF

<%@ Page Language="vb" AutoEventWireup="false"
CodeBehind="WebForm1.aspx.vb" Inherits="WebApplication1.WebForm1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>

<script type="text/javascript" language="JavaScript1.2">


function defaultButtonFunktion(evt, btn) {
var keyCode = evt.which ? evt.which : evt.keyCode;
if (keyCode == 13) {
evt.returnValue = false;
evt.cancel = true;
btn.click();
}
}
</script>

</head>
<body onkeydown="defaultButtonFunktion(event,document.getElementById('<
%=Button2.ClientID %>'))">
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button" />
<asp:Button ID="Button2" runat="server" Text="Button" />
<asp:Button ID="Button3" runat="server" Text="Button" />
</div>
</form>
</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top