lonewolf217 Posted May 30, 2009 Share Posted May 30, 2009 I have a form with all types of inputs .. text, select, checkbox, radio Is there a particular method that I could use that will trigger if any of them are changed, or will I have to call different methods for each type of input (i.e. keyup for text fields, click for submit button) say for example, can I assign a class to every input and then trigger a type of generic onchange event for that class ? Go easy on me, I am working through about a dozen tutorials online right now that each handle jquery a different way and most of them seem to only do a simple thing like generate an email based on text fields. hopefully google will come through for me soon, but its always nice to have a fallback Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 30, 2009 Share Posted May 30, 2009 Depends on what you want the onchange event to do. You can map an onchange event to every element associated with the class. Quote Link to comment Share on other sites More sharing options...
lonewolf217 Posted May 30, 2009 Author Share Posted May 30, 2009 well right now I am triggering off clicking the submit button. It kicks off a POST request to the backend page which runs the SQL query from the form fields and prints the results in a new div. This is my oversimplified version with only a single text field to test if it works or not, which it does. Now that I am sure that it works, I am looking to see what I can do with this part to allow it to trigger off of any input type, such as my dropdown menu with ID=test $("#name").keyup(function() { here is the whole pageif it matters at all <script type="text/javascript"> $(document).ready(function() { $("#name").keyup(function() { var datastring = $("input#name").val(); //alert(datastring);return false; $.post("test.php",{name:""+datastring+""},function(data) { if(data.length > 0) { $('#resources').fadeIn('slow'); $('#resources').html(data); } }); return false; }); }); </script> <form name="form"> <input type="text" name="name" id="name"> <select name="test" id="test"> <option value="1">1</option> <option value="1">2</option> </select> <input type="submit" value="Submit" id="submit"> </form> Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 30, 2009 Share Posted May 30, 2009 You want to fire off a POST request on each keyup? Well, that should work too. Sample code - jQuery('.form_inputs').keyup(function() { $.post("test.php", {name: $(this).val()}, function (data) { if (data.length > 0) { ... } }); }); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.