Solved

Javascript if on hiiden value

Posted on 2009-05-19
3
448 Views
Last Modified: 2012-06-27
I want to run part of a javascript script only if my hidden field's value is set to On.

I am getting an error from Visual Studio because the script is continuing whether the value is On or anything else.

Can you help me?
if (document.getElementById('<%=BlanketHdn.ClientID%>').value = 'On')

                    {

                        var wrapElement = document.getElementById('Blanket');

                        wrapElement.style.position = 'absolute';

                        wrapElement.style.left = '0px';

                        wrapElement.style.width = (windowWidth) + 'px';

                        wrapElement.style.top = '0px';

                        wrapElement.style.height = (windowHeight) + 'px';

                    }

Open in new window

0
Comment
Question by:CatsSolutions
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
alien109 earned 500 total points
ID: 24422532
You need a double equals sign for a comparative operation. Right now you are actually doing an assignment and it will always evaluate to true. Try this:
if (document.getElementById('<%=BlanketHdn.ClientID%>').value == 'On')
0
 

Author Closing Comment

by:CatsSolutions
ID: 31583022
I can not believe that I missed that! I feel very stupid now.

Thank you.
0
 
LVL 12

Expert Comment

by:alien109
ID: 24422615
Glad to help. And don't feel stupid - It's so easy to miss a typo in your own stuff and then keep reading how your brain knows it should be, rather than how it really is :) I think we all do that!

Cheers.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now