Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

If Select Val() = "A" then show else hide

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading