Solved

Javascript if on hiiden value

Posted on 2009-05-19
3
455 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…
Suggested Courses

623 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