I have two radio button
input type = radio name = "Level" value = "P"
input type = radio name = "Level" value = "S"
I have two textboxes:
input type = "text" name = "inpu11" disabled = "disabled"
input type = "text" name = "inpu12" disabled = "disabled"
My question is,
How Can I identify to which button I've selected ? How can I retrieve the selected rad开发者_运维技巧io Id ? I need to enable the first textbox if the selected value is "P" and disabled if 'S'
You asked 3 questions. I'll answer the third question first. You can do this with Javascript/JQuery fairly easily.
View.aspx:
<form action='/MyController/MyAction' method='post'>
<div>
<input type='radio' name='selectRadios' value='P' />
<input type='text' name='firstTextBox' value='P' />
</div>
<div>
<input type='radio' name='selectRadios' value='S' />
<input type='text' name='secondTextBox' value='S' />
</div>
<input type='submit' value='Submit Values to ActionMethod' />
</form>
<script type='text/javascript'>
$(document).ready(function() {
$("input[name=selectRadios]").click(function() {
switch($(this).val()) {
case 'S':
$("input[name=firstTextBox]").attr("disabled", "disabled");
break;
case 'P':
$("input[name=firstTextBox]").attr("disabled", "");
break;
}
});
});
</script>
I think your first and second questions will get answered pretty easily by MVC's modelbinder.
MyController.cs (action method only):
//argument names match form element names from view.aspx
public ActionResult MyAction(string selectRadios, string firstTextBox, string secondTextBox)
{
//do something with your form values
}
精彩评论