jquery - how it possible.? add runtime dropdown text and value -
mr. los frijoles plz show question , answer. how possible.? have 2 drop down , 1st static 'drpdisplayans1' , 2nd 'drpcorrectans1' here select 'drpdisplayans1' option 2 1 , 2 in 'drpcorrectans1' 2nd drop down, or select 3 1, 2 , 3 in 'drpcorrectans1' 2nd drop down, or select 4 1, 2, 3 , 4 in 'drpcorrectans1' 2nd drop down. means add runtime using jquery. or etc. how possible.? in mvc razor. plz me. thnks.
my view code is
'<div class="editor-field"> @html.dropdownlistfor(model => model.displayanswer, new selectlist(new[] { new { value="2", text="2"}, new { value="3", text="3"}, new { value="4", text="4"}, }, "value", "text", 4), new{ id= "drpdisplayans1"})' '@html.validationmessagefor(model => model.displayanswer) </div> <div class="editor-label1"> @html.labelfor(model => model.answer1) @html.editorfor(model => model.answer1) @html.validationmessagefor(model => model.answer1) </div> <div class="editor-label2"> @html.labelfor(model => model.answer2) @html.editorfor(model => model.answer2) @html.validationmessagefor(model => model.answer2) </div> <div class="editor-label3"> @html.labelfor(model => model.answer3) @html.editorfor(model => model.answer3) @html.validationmessagefor(model => model.answer3) </div> <div class="editor-label4"> @html.labelfor(model => model.answer4) @html.editorfor(model => model.answer4) @html.validationmessagefor(model => model.answer4) </div> <div class="editor-label"> @html.labelfor(model => model.correctanswer) </div> <div class="editor-field"> @html.dropdownlistfor(model => model.correctanswer, new selectlist(new[] { new {value="0", text=" "}, new {value="1", text="1"}, new {value="2", text="2"}, new {value="3", text="3"}, new {value="4", text="4"}, }, "value", "text", 0), new{id="drpcorrectans1"}) @html.validationmessagefor(model => model.correctanswer) </div>'
and script file
'$(document).ready(function () { $('#drpdisplayans1').change(function () { if (this.value == '2') { $('.editor-label1').show(); $('.editor-label2').show(); $('.editor-label3').hide(); $('.editor-label4').hide(); } else if (this.value == '3') { $('.editor-label1').show(); $('.editor-label2').show(); $('.editor-label3').show(); $('.editor-label4').hide(); } else if (this.value == '4') { $('.editor-label1').show(); $('.editor-label2').show(); $('.editor-label3').show(); $('.editor-label4').show(); } });
});'
mr.los frijoles not ask fake questions.
and question's answer following. r u understand mr. los frijoles..??
<div class="editor-field"> @html.dropdownlistfor(model => model.displayanswer, new selectlist(new[] { new { value="2", text="2"}, new { value="3", text="3"}, new { value="4", text="4"}, }, "value", "text", 4), new{ id= "drpdisplayans1"})' '@html.validationmessagefor(model => model.displayanswer) </div> <div class="editor-label1"> @html.labelfor(model => model.answer1) @html.editorfor(model => model.answer1) @html.validationmessagefor(model => model.answer1) </div> <div class="editor-label2"> @html.labelfor(model => model.answer2) @html.editorfor(model => model.answer2) @html.validationmessagefor(model => model.answer2) </div> <div class="editor-label3"> @html.labelfor(model => model.answer3) @html.editorfor(model => model.answer3) @html.validationmessagefor(model => model.answer3) </div> <div class="editor-label4"> @html.labelfor(model => model.answer4) @html.editorfor(model => model.answer4) @html.validationmessagefor(model => model.answer4) </div> <div class="editor-label"> @html.labelfor(model => model.correctanswer) </div> <div class="editor-field"> @html.dropdownlistfor(model => model.correctanswer, new selectlist(new[] { new {value="0", text=" "}, new {value="1", text="1"}, new {value="2", text="2"}, new {value="3", text="3"}, new {value="4", text="4"}, }, "value", "text", 0), new{id="drpcorrectans1"}) @html.validationmessagefor(model => model.correctanswer) </div>
and script code is:
$(document).ready(function () { $('#drpdisplayans1').change(function () { if (this.value == '2') { $('.editor-label1').show(); $('.editor-label2').show(); $('.editor-label3').hide(); $('.editor-label4').hide(); $("#drpcorrectans1 option[value='3']").attr("disabled", true).hide(); $("#drpcorrectans1 option[value='4']").attr("disabled", true).hide(); } if (this.value == '3') { $('.editor-label1').show(); $('.editor-label2').show(); $('.editor-label3').show(); $('.editor-label4').hide(); $("#drpcorrectans1 option[value='3']").attr("disabled", false).show(); $("#drpcorrectans1 option[value='4']").attr("disabled", true).hide(); } if (this.value == '4') { $('.editor-label1').show(); $('.editor-label2').show(); $('.editor-label3').show(); $('.editor-label4').show(); $("#drpcorrectans1 option[value='3']").attr("disabled", false).show(); $("#drpcorrectans1 option[value='4']").attr("disabled", false).show(); } });
Comments
Post a Comment