javascript - Using jQuery event handlers - jQuery newbie -


i'm in process of learning jquery , feel must missing something. have super simple form set below:

<form name="testform" id="testform" method="post">     <select type="select" id="searchid">         <option value="1">option 1</option>         <option value="2">option 2</option>     </select>     <input type="text" id="searchtext" value="$_post['value']"> </form> 

i'd use jquery automatically submit form when #searchid changed. understand how basic javascript, need jquery other things , need learn how these things work. below jquery snippet seems me should work, it's not working. ideas why?

$( "#searchid" ).change( function() {     $( "#testform" ).submit(); }) 

this how can submit form:

$(function() {     $( "#searchid" ).change( function() {         $( "#testform" )[0].submit();         //or this.form.submit();     }); }); 

quite close indeed. make sure server-side receive proper data, your inputs should have names.

edit

the code has been updated include dom ready. it's easy assume dom ready fundamental , may not issue. however, it's never safe make assumptions.

please note when creating demos on js fiddle, may not required use dom ready if drop down under jquery version selector says 'onload' or 'ondomready' ... .. code wrapped in appropriate event handler js fiddle anyway.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -