I am trying to hide a text box if a certain value is present.
I cannot figure out what is wrong with my statement:
if ($('#DisplayFlag').val() === "Positive") {
$("#TestingTextBox").show();
}
else {
$("#TestingTextBox").hide();
}
My DisplayFlag value is pulled via a stored procedure and returns only 1 value. I show this value on my page, so i can see the value "Positive" displayed. Here is the excerpt for that:
<div class="form-group has-feedback elem-margin" id="DisplayFlag">
@Html.LabelFor(model => model.DisplayFlag): @Html.EditorFor(model => model.DisplayFlag, new { htmlAttributes = new { @class = "readonly-field-right", @readonly = "readonly" } })
</div>
Also my TestingTextBox is that i want to hide/show:
<div class="form-group has-feedback elem-margin" id="TestingTextBox">
<div>
<label for="TestingTextBox">Testing text box</label>
</div>
<div>@Html.RadioButtonFor(model => model.TestingTB, 1, new { @id = "testYes" }) Yes</div>
<div>@Html.RadioButtonFor(model => model.TestingTB, 0, new { @id = "testNo" }) No</div>
</div>
Thanks for any help. i can provide more info if needed.
I have tried adjusting the query multiple times to show/hide in different ways. val() and text() did not work.
>Solution :
A <div> element doesn’t have a "value". It looks like you meant to select an <input> within that <div>:
$('#DisplayFlag input').val()
You can of course check your resulting HTML in the browser to see the exact markup being generated and identify the exact element you want to target. But just targeting the <div> won’t get you another element’s value.