Solved

Javascript if on hiiden value

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

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'…
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…

820 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