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...
  3. Page Load Speed Part of Google’s Algorithm Following on from our post the other day (SwiftRank...
  4. The Best Place to Put SEO Copy on Your Web Page It seems like a funny question to me, but...
  5. SwiftRank By Optimizing Page Speed Google algorithm changes are a big deal for all...

Post a Comment