admin管理员组文章数量:1335362
I have javascript that controls certain div tags that hide or show upon checked state. I then pass these values when i submit form. Thing is, values from fields in the div tag that were hidden get passed as well. How do i not pass these values?
My HTML / Javascript is as follows :
<div id="divShortAnswerQuestion">
<h2>Short Answer Question</h2>
<!--Question Order-->
<asp:Label ID="Label2" runat="server" Text="Question Order"></asp:Label>
<%=Html.TextBox("QuestionOrder")%>
<br />
<!--Partial Answers-->
<asp:Label ID="Label5" runat="server" Text="Allow Partial Answers"></asp:Label>
<%=Html.RadioButton("PartialAnswers", "1", true) %>Yes
<%=Html.RadioButton("PartialAnswers", "0", false) %>No
<br />
<!--Max Answers-->
<asp:Label ID="Label6" runat="server" Text="Max Answers (1-10)"></asp:Label>
<%=Html.TextBox("Max") %>
<br />
<!--Data Type-->
<asp:Label ID="Label7" runat="server" Text="Data Type"></asp:Label>
<%=Html.DropDownList("DataType", new List<SelectListItem>
{
new SelectListItem{Text="Numeric", Value = "Numeric"},
new SelectListItem{Text="Alphanumeric", Value = "Alphanumeric"},
new SelectListItem{Text="Date", Value = "Date"}
}) %>
<br />
<!--Question Type-->
<asp:Label ID="Label13" runat="server" Text="Question Type"></asp:Label>
<%=Html.DropDownList("QuestionType", new List<SelectListItem>
{
new SelectListItem{Text="Numeric", Value = "6"},
new SelectListItem{Text="Alphanumeric", Value = "7"}
}) %>
</div>
And my Javascript is something like:
$("input:radio[@name=QuestionGroup]").click(function() {
var checkedvalue = $(this).val();
if(checkedvalue=="1"){
$('#divShortAnswerQuestion').hide();
$('#divMultipleChoiceQuestion').show();
$('#divParticipantListQuestion').hide();
}
if(checkedvalue=="2"){
$('#divMultipleChoiceQuestion').hide();
$('#divShortAnswerQuestion').show();
$('#divParticipantListQuestion').hide();
}
if(checkedvalue=="3"){
$('#divMultipleChoiceQuestion').hide();
$('#divShortAnswerQuestion').hide();
$('#divParticipantListQuestion').show();
}
});
So how would one go about not passing empty or any elements in a hidden div tag on a form submit?
I have javascript that controls certain div tags that hide or show upon checked state. I then pass these values when i submit form. Thing is, values from fields in the div tag that were hidden get passed as well. How do i not pass these values?
My HTML / Javascript is as follows :
<div id="divShortAnswerQuestion">
<h2>Short Answer Question</h2>
<!--Question Order-->
<asp:Label ID="Label2" runat="server" Text="Question Order"></asp:Label>
<%=Html.TextBox("QuestionOrder")%>
<br />
<!--Partial Answers-->
<asp:Label ID="Label5" runat="server" Text="Allow Partial Answers"></asp:Label>
<%=Html.RadioButton("PartialAnswers", "1", true) %>Yes
<%=Html.RadioButton("PartialAnswers", "0", false) %>No
<br />
<!--Max Answers-->
<asp:Label ID="Label6" runat="server" Text="Max Answers (1-10)"></asp:Label>
<%=Html.TextBox("Max") %>
<br />
<!--Data Type-->
<asp:Label ID="Label7" runat="server" Text="Data Type"></asp:Label>
<%=Html.DropDownList("DataType", new List<SelectListItem>
{
new SelectListItem{Text="Numeric", Value = "Numeric"},
new SelectListItem{Text="Alphanumeric", Value = "Alphanumeric"},
new SelectListItem{Text="Date", Value = "Date"}
}) %>
<br />
<!--Question Type-->
<asp:Label ID="Label13" runat="server" Text="Question Type"></asp:Label>
<%=Html.DropDownList("QuestionType", new List<SelectListItem>
{
new SelectListItem{Text="Numeric", Value = "6"},
new SelectListItem{Text="Alphanumeric", Value = "7"}
}) %>
</div>
And my Javascript is something like:
$("input:radio[@name=QuestionGroup]").click(function() {
var checkedvalue = $(this).val();
if(checkedvalue=="1"){
$('#divShortAnswerQuestion').hide();
$('#divMultipleChoiceQuestion').show();
$('#divParticipantListQuestion').hide();
}
if(checkedvalue=="2"){
$('#divMultipleChoiceQuestion').hide();
$('#divShortAnswerQuestion').show();
$('#divParticipantListQuestion').hide();
}
if(checkedvalue=="3"){
$('#divMultipleChoiceQuestion').hide();
$('#divShortAnswerQuestion').hide();
$('#divParticipantListQuestion').show();
}
});
So how would one go about not passing empty or any elements in a hidden div tag on a form submit?
Share Improve this question edited Feb 8, 2018 at 5:39 ʇolɐǝz ǝɥʇ qoq 7341 gold badge16 silver badges31 bronze badges asked May 27, 2011 at 12:40 Hriskesh AshokanHriskesh Ashokan 7815 gold badges16 silver badges28 bronze badges1 Answer
Reset to default 7In addition to hiding the div you could disable the input elements inside it and they will not be sent to the server:
$('#divMultipleChoiceQuestion').hide();
$('#divMultipleChoiceQuestion :input').attr('disabled', 'disabled');
Don't forget to re-enable them when you show the div:
$('#divMultipleChoiceQuestion').show();
$('#divMultipleChoiceQuestion :input').removeAttr('disabled');
You could write a plugin that will do this to avoid repeating the code all over again, so that all you need to do is:
$('#divMultipleChoiceQuestion').toggleVisibility();
本文标签: javascriptNot pass values from hidden div tag in a form when submittedStack Overflow
版权声明:本文标题:javascript - Not pass values from hidden div tag in a form when submitted - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742357445a2459699.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论