views:

772

answers:

2

As everyone knows, that default button doesn't work in FF, only IE. I've tried to put in the tag or in the and it's not working. I've found a js script to fix this issue, but for some reason it's not working for me. This script for a submit button, i need to use it for a LinkButton, which is should be the same.

Link:

  <div id="pnl">
    <a id="ctl00_cphMain_lbLogin" title="Click Here to LogIn" href="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$cphMain$lbLogin&quot;, &quot;&quot;, true, &quot;Login1&quot;, &quot;&quot;, false, true))">Log In</a>
    <input name="ctl00$cphMain$UserName" type="text" id="ctl00_cphMain_UserName" />
    <input name="ctl00$cphMain$UserName" type="text" id="ctl00_cphMain_UserName1" />
  </div>

<script>

 $(document).ready(function() {
    $("#pnl").keypress(function(e) {
        if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
            $("a[id$='_lbLogin']").click();
            return true;
        }
    });
});

I know that i can override original function "*WebForm_FireDefaultButton*" in This post, but i really wanted to get this one to work.

Thanx in advance!!!

A: 

You could expand your selector.

$("#pnl > input")

Which will then catch the input click for all the controls in the panel.

Chris Brandsma
Looks Good, but what if some1 highlights text in this panel/div and press ENTER?
pyccki
A: 

I found the answer to fixing linkbuttons here: http://www.sentia.com.au/2009/03/fixing-the-enter-key-in-aspnet-with-jquery/

$(document).ready(function(){
  var $btn = $('.form_submit');
  var $form = $btn.parents('.form');

  $form.keypress(function(e){
      if (e.which == 13 && e.target.type != 'textarea') {
          if ($btn[0].type == 'submit')
              $btn[0].click();
          else
              eval($btn[0].href);
          return false;
      }
  });
});
Larry Flewwelling
Larry, This works. Thank you.
pyccki