Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want when the label content is Laptop hidden-panel2 and hidden-panel3 to be hidden and only hidden-panel to be shown. when I create the record from within the application it is working fine but when the record is added from the database it is not. what am I doing wrong.

What I have tried:

HTML
<label id="AssetType"> @Html.DisplayFor(model => model.AType </label>


Divs to hide

HTML
<div id="hidden-panel">
     <label class="label">@Html.DisplayFor(model => model.LaptopProcess)</label>
</div>

<div id="hidden-panel2">
     <label class="label">@Html.DisplayFor(model => model.pcProcess)</label>
</div>

<div id="hidden-panel3">
     <label class="label">@Html.DisplayFor(model => model.phoneProcess)</label>
</div>


Script to hide Divs

JavaScript
$(document).ready(function () {
    $("#AssetType").ready(function () {
        if ($('#AssetType').text() == 'Laptop') {
            $('#hidden-panel').show();
            $('#hidden-panel2').hide();
            $('#hidden-panel3').hide()
        }
    })
});
Posted
Updated 4-Jul-21 22:45pm
Comments
gggustafson 4-Jul-21 15:30pm    
This is jQuery. Please correct your tags.

1 solution

JavaScript
$(function(){
    const assetType = $("#AssetType").text().trim();
    if (assetType === "Laptop") {
        $("#hidden-panel2").hide();
        $("#hidden-panel3").hide();
    }
});
If it still doesn't work, then you need to debug your code to find out what the actual value of the AssetType label is.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900