problem with defaultbutton cross browser

  • Thread starter Thread starter PNR
  • Start date Start date
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
 
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>
 
Back
Top