Do not pass values ​​from a hidden div tag in the form when submitting

I have javascript that manages certain div tags that are hidden or displayed when checking status. Then I pass these values ​​when I submit the form. The thing is, values ​​from fields in the div tag that were hidden are also passed. How can 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 could one skip the void or any elements in a hidden div tag on the submit form?

+3
source share
1 answer

In addition to hiding the div, you can disable input elements inside it and they will not be sent to the server:

$('#divMultipleChoiceQuestion').hide();
$('#divMultipleChoiceQuestion :input').attr('disabled', 'disabled');

, div:

$('#divMultipleChoiceQuestion').show();
$('#divMultipleChoiceQuestion :input').removeAttr('disabled');

, , , , , :

$('#divMultipleChoiceQuestion').toggleVisibility();
+6

All Articles