admin管理员组文章数量:1394526
This is going to be a stupid question but i need to ask it.
PS: this is an old practice but i need it this way.
In scriptlet I have a variable status
.
<%
String status=bean.getStatus();
//Status value is ing from database which is either "1" or "0"(String type)
%>
In a form I have radio button.
<tr>
<td> Status :</td>
<td>Active
<input type="radio" name="status" checked="checked" id="statusAct" value="1" />
Inactive
<input type="radio" name="status" id="statusInac" value="0"/>
</tr>
If status==1
I want radio button with id="statusAct"
to be selected and if status==0
then radio with id="statusInac"
to be selected.
I can use javascript or Jquery but I don't know how to put Java variable inside javascript function.
This is going to be a stupid question but i need to ask it.
PS: this is an old practice but i need it this way.
In scriptlet I have a variable status
.
<%
String status=bean.getStatus();
//Status value is ing from database which is either "1" or "0"(String type)
%>
In a form I have radio button.
<tr>
<td> Status :</td>
<td>Active
<input type="radio" name="status" checked="checked" id="statusAct" value="1" />
Inactive
<input type="radio" name="status" id="statusInac" value="0"/>
</tr>
If status==1
I want radio button with id="statusAct"
to be selected and if status==0
then radio with id="statusInac"
to be selected.
I can use javascript or Jquery but I don't know how to put Java variable inside javascript function.
Share Improve this question asked Jun 23, 2013 at 21:12 AzAhAzAh 411 gold badge1 silver badge14 bronze badges 1-
1
Maybe
var status = "<% string......%>";
and thenif(status == '1') { $('#id').prop('checked', true); }
– Omar Commented Jun 23, 2013 at 21:16
2 Answers
Reset to default 2You can simply do
<input type="radio" name="status" <% ${bean.getStatus() == '1' ? 'checked="checked"' : '' } %> id="statusAct" value="1" />
and
<input type="radio" name="status" <% ${bean.getStatus() == '0' ? 'checked="checked"' : '' } %> id="statusInac" value="1" />
Either use scriptlets to do conditional logic and write checked ="checked" where you need to. In the scriptlets you can do out. println to write to the page (output stream). You could also use jstl for condition tags c:if
本文标签: javascriptchecked radio button from JSP scriptlet variableStack Overflow
版权声明:本文标题:javascript - checked radio button from JSP scriptlet variable - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744099919a2590827.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论