Destramic Posted March 13, 2011 Share Posted March 13, 2011 hey guys im trying to get the correct alert when the form is being used....for instance if a user changed the input value i want it to alert input...if checkbox is checked alert checkbox....and the same with select if option is selected but all i get is the script alerting input anytime i do anything to any field can someone please help me on how to divide these fields apart from each other....thank you <!DOCTYPE html> <html> <head> <script type="text/javascript" src="js/library/jquery.js"></script> <script type="text/javascript" src="js/library/jquery.cookie.js"></script> <style> div { display : inline; } </style> </head> <body> <script> $(document).ready(function() { function remember_field_value(selector) { $(selector).change(function() { if ($(selector + ':checkbox')) { alert('checkbox'); } else if ($(selector + ':input')) { alert('input'); } else if ($(selector + ':selected')) { alert('select'); } }); } remember_field_value('input#game_type1'); remember_field_value('input#tester'); remember_field_value('select#game'); }); </script> <form method="post"> <input id="game_type1" name="game_types[]" value=""/> <input id='tester' type="checkbox" name="team" value="other"> <select id='game'> <option>hello</option> <option>bye</option> </select> <input type="submit" value="Submit"> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/230507-selector-type-inputcheckboxselect/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.