I would like to display a textbox depending on the value selected in the Html.DropDownList. Is this possible?
+2
A:
Display where? Show/Hide a textbox depending on value in a drop down?
You could easily achieve this using the change event and jquery. Something like (untested)
$('#dropdownId').change(function(){
var textbox = $('#textboxId');
if ($(this).val() == 'foo')
textbox.hide();
else
textbox.show();
});
Fermin
2009-11-24 11:30:18
Thank you for your help, that's it working now.
Roslyn
2009-11-24 12:32:40
A:
You'll have to use javascript for that. Add an onchange event for the dropdownlist. Something like:
<%= Html.DropDownList("myList", myData, new { onchange = "showTextBox(this)" }) %>
And your myFunc will look along the lines of:
function showTextBox(item) {
if(item.value == 'theCorrectValue')
{
document.getElementById('myTextBox').style.visibility = 'visible';
}
}
If you use jQuery, it'll be slightly easier
Razzie
2009-11-24 11:31:03