Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-29-2013, 12:08 PM   PM User | #1
johnsmith153
New Coder

 
Join Date: Mar 2012
Posts: 81
Thanks: 7
Thanked 0 Times in 0 Posts
johnsmith153 is infamous around these parts
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.
johnsmith153 is offline   Reply With Quote
Old 01-29-2013, 02:20 PM   PM User | #2
SB65
Senior Coder

 
Join Date: Feb 2009
Location: West Yorkshire
Posts: 2,817
Thanks: 9
Thanked 681 Times in 675 Posts
SB65 will become famous soon enoughSB65 will become famous soon enough
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
SB65 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


Advertisement
Log in to turn off these ads.