javascript - Activate radiobutton when text box is selected -


i trying setup javascript form validation on form working on. have of validation working, 1 thing have been tasked doing can't seem figure out , can't find many articles online it.

the challenge have if user wants type in "other" field on text box want "other" radio button automatically checked. here's code had in there isn't working me.

if (f.othertextvalue.value !== '') {     document.getelementbyid("othertextradio").checked = true;     return false; } 

so think trying this: if othertextvalue (my text box) not blank go id of radio button , make checked/selected.

i still new in world of javascript, trying learn.

thank help.

bind event handler text element, , set state of checkbox according whether there value or not:

$('#othertextvalue').on('keyup', function() {   $('#othertextradio').prop('checked', !!this.value.length); }); 

you may want use additional events, triggers when key released. check documentation

here's simple example


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -