Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Mar 2012
    Posts
    81
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Please help to improve my code

    Code:
    $("select").change(function () {
      function_name($(this));
    });
    $("textarea").change(function () {
      function_name($(this));
    });
    $("input").change(function () {
       function_name($(this));
    });
    I'm sure the above code can be improved. Also, I understand the above won't target radio and checkboxes, is that right? Basically I want all form elements (not necessarily always inside a <form> tag though) to trigger a script after entering text/data in them.

    Thanks for any help.

  • #2
    Senior Coder
    Join Date
    Feb 2009
    Location
    Ilkley, West Yorkshire, UK
    Posts
    2,956
    Thanks
    9
    Thanked 727 Times in 721 Posts
    Code:
    $("select, textarea, input").change(function () {
      function_name($(this));
    });
    is shorter. All input elements will be included with this selector.
    Use the W3C HTML Validator and CSS Validator to check your code and Firebug to see what css is applied to an element
    Read Steve Krug's book Don't Make Me Think - essential reading on web usability
    I don't recommend much, but I do recommend Clook for UK web hosting


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •