jquery - Trying to programmatically set select option value not working -
i trying programmatically set select list option value being selected.
<script> if(typeof localstorage.me !== "undefined") { console.log("test"); $("#business").val(localstorage.me); } if(typeof localstorage.partner !== "undefined") { $("#partner-business").val(localstorage.partner); } $("#page-main").on("change", "#business", function(event) { localstorage.setitem("me", $("#business").val()); }); $("#page-main").on("change", "#partner-business", function(event) { localstorage.setitem("partner", $("#partner-business").val()); }); </script> <div class="content" data-role="content"> <div data-role="fieldcontain"> <h3 class="select center-h3">i a:</h3> <select name="business" id="business"> <option value="technical">technical</option> <option value="sales">sales</option> </select> </div> <div data-role="fieldcontain"> <h3 class="select center-h3">my partner a:</h3> <select name="partner-business" id="partner-business"> <option value="technical">technical</option> <option value="sales">sales</option> </select> </div> </div>
i trying set based on option value, doesn't seem work.
how set option value , not name inside option tags?
you need wrap code in document-ready handler. apart code works.
specify function execute when dom loaded.
$(document).ready(function () { //your code });
Comments
Post a Comment