javascript - How to trigger different functions based on a radio button option? -
i'm having troubles trying trigger 2 different functions based on radio button option.
i have autocomplete field, source must setted radiobutton option. can do?
i have done this, far:
var autocompleteone = [ "item 01", "item 02", "item 03", "item 04", "item 05" ]; var autocompletetwo = [ "item 01.2", "item 02.2", "item 03.2", "item 04.2", "item 05.2" ]; $('#options').blur(function(){ if(document.getelementbyid("optiona").attr(checked, true{ $("#autocompletecaseone").autocomplete({ source: autocompleteone }); } if(document.getelementbyid("optionb").attr(checked, true{ $("#autocompletecasetwo").autocomplete({ source: autocompletetwo }); } });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> <div> <label>choosing option</label> <input type="radio" name="options" value="yes" id="optiona" />yes <input type="radio" name="options" value="no" id="optionb" />no </div> <div> <label>autocomplete function result</label> <input type="text" id="options" name="autocompleteoptions"> </div>
thanks
it correct, autocomplete function not correct. following correct full code.
$("input[name='options']").change(function(event) { if ($(this).val() == "yes") $("#options").autocomplete({ source: autocompleteone }); else if ($(this).val() == "no") $("#options").autocomplete({ source: autocompletetwo }); });
Comments
Post a Comment