Top SEM and SEO Tips   

jQuery – Add a default button to a page

December 29, 2008 – 5:59 pm

Normally in HTML you can add a ‘input type=”submit”‘ to a page and it acts as a default button. However this only works if the input tag is within a ‘form’. I was using AJAX and found that adding a form caused the AJAX to fail. Instead I ended up with the following code:

$(‘input’).keyup(function(e) {
//alert(e.keyCode);
if(e.keyCode == 13) {
$(‘#btnSubmit’).click() ;
}
});

This adds to all input fields a keyup function that checks for the enter key and if found calls the click function on the button I want to use as the default button – in this case it’s an input button called ‘btnSubmit’.

Related posts:

  1. jQuery Automatic Trim of Input Fields Really common task with a really easy solution $(function() {...
  2. Save HTML Table to Excel using jQuery After a few hours work looking into this, this turned...
  3. Page Load Speed Part of Google’s Algorithm Following on from our post the other day (SwiftRank By...
  4. The Best Place to Put SEO Copy on Your Web Page It seems like a funny question to me, but it...
  5. Review: Landing Page Handbook: How to Raise Conversions by Karon Thackston © 2005 http://www.marketingwords.com/landingpage.html If you’ve been online...
  1. One Response to “jQuery – Add a default button to a page”

  2. Tried it and works great.
    Thanks.

    By Ben Mallari on Apr 28, 2010

Post a Comment