Link to home
Start Free TrialLog in
Avatar of jknj72
jknj72

asked on

Javascript to set controls visibility

I have a web page with a datalist. I have images displayed in the Datalist depending on a status certain images would be visible or not.

Status = 2,5,8 then imgPending.Visible = true
Status = 3,6,9 then imgApproved.Visible=true
Status 4,7,10 then imgRejected.Visible = true

I had in the markup of each of these images only for 1 status and as more statuses got added I have to code for this.
This is what I had in my markup prior to the new statuses being added

<asp:image id=imgPending runat="server" ImageUrl="~/images/hourglass.png"  Visible='<%# IIf(DataBinder.Eval(Container.DataItem, "StatusID") = 2, "True", "False")%>'

Open in new window


Id like to add a javascript function that I can set the visibility.   Something like below

   function setImages(status) {
        var answer;
        switch (val) {
            case 2: case 5: case 8:
                answer = "True";
                break;
            case 3: case 6: case 9:
                answer = "True";
                break;
            case 4: case 7: case 10:
                answer = "True";
                break;
            default:
                answer = "False";
        }
       return answer;
    }

Open in new window


and then the image for Pending would be something like  Visible=setImages(2,5,8)
I just dont know how to write this correclty

Thanks
JK
Avatar of Alexandre Simões
Alexandre Simões
Flag of Switzerland image

You're using server-side controls and trying to manipulate them with JavaScript which usually carries some extra amount of work.

Are the images URL static of do they change based on some server-side logic?
What defines the status? Is it server-side logic or client-side user actions?

Depending on the above, you should act differently, putting the logic on the client or on the server.

Let me know,
Alex
Avatar of jknj72
jknj72

ASKER

Status changes with server side logic. Most or all of the code is done server side but occasionally, if I can, i will use some javascript to do some of the work for me. So in this instance, depending on the status I set the visibility of images that I need to display. If I can do this on the client side it would help me out.
ASKER CERTIFIED SOLUTION
Avatar of Alexandre Simões
Alexandre Simões
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jknj72

ASKER

I appreciate your help but its not what I was looking for. I want to call a javascript function to set my images visible or not.
Avatar of jknj72

ASKER

thx