Solved

Javascript if on hiiden value

Posted on 2009-05-19
3
449 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

910 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

24 Experts available now in Live!

Get 1:1 Help Now