javascript - Setting HTML drop down list option -


i trying set value php option selected in drop down list in html. can tell me how give "selected" attribute answer generated dynamically

<select form="onsite_assessment" class="form-control" id="onsite_assessment">         <option value="no">no</option>         <option value="yes">yes</option>     </select> 

in above code if user has selected no in previous session. want display option default.

this general code can shaped needs. can't see code cannot give full answer. need store users' choice , retrieve in variable whenever needed, either string or boolean (true/false). in example show using string.

<?php   $user_choice = 'yes'; ?>  <select form="onsite_assessment" class="form-control" id="onside_assessment">   <option value="no" <?php if($user_choice == 'no'){echo 'selected'; }>no</option>   <option value="yes" <?php if($user_choice == 'yes'){echo 'selected'; }>yes</option> </select> 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -