javascript - Auto-select Radio Button with Text Field? -


did lots of searching on here , found plenty of people similar questions, every 'solution' have found fails work in case. missing simple, or may have our html. basically, want our text field check it's corresponding radio button should enter value there.

here jsfiddle want working, when put host on server testing don't same result.

jsfiddle

http://jsfiddle.net/p8kvq/39/

html

<div>   <input type="radio" name="unitprice1" id="unitprice1" value="47" checked="checked" />   <label for="unitprice1">$47</label> </div>  <div>   <input type="radio" name="unitprice1" id="unitprice2" value="other" />   <label for="unitprice2">other</label>   <input class="-input-width-auto" name="other1" type="number" id="other1" /> </div> 

js

$('#other1').click(function(){   $('#unitprice2').trigger('click'); }); 

i have "http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js" defined in our html header , i've tried adding code defining source file, still no luck.

any great.

your js needs inside document.ready. when code run, dom element not available, there click listener can not attached it.

$( document ).ready(function() {   $('#other1').click(function(){      $('#unitprice2').trigger('click');   }); }); 

(jsfiddle because have following setting: http://screencast.com/t/5wuc33dihptb)


Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -