<select name="securityq1" class="selectInput">
<option value="">Please select</option>
<option value="What is your matric no?">What is your matric no?</option>
<option value="What is the name of your lover?" >What is the name of your lover?</option>
<option value="What is your profession?" >What is your profession?</option>
</select>
<select name="securityq1" class="selectInput">
<option value="">Please select</option>
<option value="What is your matric no?">What is your matric no?</option>
<option value="What is the name of your lover?" >What is the name of your lover?</option>
<option value="What is your profession?" >What is your profession?</option>
</select>
Hi all, this is my security question, when I want to do the update function, I want to draw from the database the question users have previously entered. If questions are little, I can do stupidly <option value="What is your matric no?" <?php if($database['securityq1']=="What is your matric no") echo "selected"; ?>>...</option>
But the security questions may up to 15 questions, do this way is very tedious? As I am using jQuery for UI , how can I make a quick way using jQuery? Thanks for help
You have to determine the selected value somehow on the server-side. I'd suggest that you keep the options in an array or some other collection and loop over them:
$options = array("What is your matric no?", ...);
foreach($options as $option) {
echo "<option value=\"$option\"";
if($database['securityq1'] === $option) {
echo ' selected';
}
echo ">$option</option>";
}
You can wrap the routine in a function and handle all similar situations easier.
If you insist using jQuery you can do something like this
发布评论
评论(2)
您必须在服务器端以某种方式确定所选值。我建议您将选项保留在数组或其他集合中并循环它们:
您可以将例程包装在函数中并更轻松地处理所有类似的情况。
如果你坚持使用 jQuery,你可以这样做,
其中
selectedSecurityQuestion
在某处定义。 查看实际效果。但是,如果关闭 javascript,此解决方案将不起作用。这是否是一个问题由目标受众决定。
You have to determine the selected value somehow on the server-side. I'd suggest that you keep the options in an array or some other collection and loop over them:
You can wrap the routine in a function and handle all similar situations easier.
If you insist using jQuery you can do something like this
Where
selectedSecurityQuestion
is defined somewhere. See it in action.However,this solution won't work if javascript is turned off. Whether that is a problem is determined by the target audience.
尝试一次..
try with this once ..