CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript frameworks (http://www.codingforums.com/forumdisplay.php?f=62)
-   -   Please help to improve my code (http://www.codingforums.com/showthread.php?t=286626)

johnsmith153 01-29-2013 12:08 PM

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.

SB65 01-29-2013 02:20 PM

Code:

$("select, textarea, input").change(function () {
  function_name($(this));
});

is shorter. All input elements will be included with this selector.


All times are GMT +1. The time now is 05:52 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.