Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 504
  • Last Modified:

JavaScript Style ID

Hello,

I am trying to make my JavaScript identify an inline style and then style two other elements based on that, here is what I have so far:

Start JavaScript
id=nice1 if style = display: inline;
then
id=nice2 style = display: none;
id=nice3 style = height: 500;
else
id=nice1 if style = display: none;
then
id=nice2 style = display: inline;
id=nice3 style = height:  800;
End

Not sure why my JavaScript I made is not working, but I would love some help making it work.
0
Richard Morris
Asked:
Richard Morris
  • 4
  • 2
1 Solution
 
leakim971PluritechnicianCommented:
why don't you post your true javascript? and the content of your page?
0
 
Richard MorrisAuthor Commented:
This is my true JavaScript, I wrote it myself.

Here is a sample page:

<html>
<head>

Start JavaScript
id=nice1 if style = display: inline;
then
id=nice2 style = display: none;
id=nice3 style = height: 500;
else
id=nice1 if style = display: none;
then
id=nice2 style = display: inline;
id=nice3 style = height:  800;
End

</head>
<body>

<div id="nice1" style="display: inline;">text</div>

<div id="nice2">text</div>

<iframe id="nice3">text</iframe>

</body>
</html>

As you can see I almost have it but can't figure out why it isn't working yet?

I just want to control ids nice2 and nice3 based on the inline style of id nice1.

Example:

if id nice1 is display: inline then id nice2 style display: none id nice3 style height: 500

if id nice1 is display: none then id nice2 style display: inline id nice3 style height: 800
0
 
leakim971PluritechnicianCommented:
try to do the work with the following : http://jsfiddle.net/CPRYs/
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
leakim971PluritechnicianCommented:
//Start JavaScript
window.onload = function() {
//id=nice1 if style = display: inline;
    var nice1 = document.getElementById("nice1");
    if(nice1.style.display=="inline")          
//then
    {
//id=nice2 style = display: none;
        document.getElementById("nice2").style.display=="none";
//id=nice3 style = height: 500;
        document.getElementById("nice2").style.height=="500px";
//else
    }
//id=nice1 if style = display: none;
    else if(nice1.style.display=="none")        
//then
    {
//id=nice2 style = display: inline;
        document.getElementById("nice2").style.display=="inline";
//id=nice3 style = height:  800;
        document.getElementById("nice2").style.height=="800px";
//End
    }
}

Open in new window

¿
0
 
Richard MorrisAuthor Commented:
Still doesn't work for me, here is what I have so far:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>

<script type="text/javascript">
window.onload = function() {
    var nice1 = document.getElementById("nice1");
    if(nice1.style.display=="inline")          
    {
        document.getElementById("nice2").style.display=="none";
        document.getElementById("nice3").style.height=="500px";
    }
    else if(nice1.style.display=="none")        
    {
        document.getElementById("nice2").style.display=="inline";
        document.getElementById("nice3").style.height=="800px";
    }
} 
</script>

</head>
<body>

<div id="nice1" style="display: inline;">text</div>

<div id="nice2">text</div>

<iframe id="nice3">text</iframe>

</body>
</html>

Open in new window

0
 
jrm213jrm213Commented:
Just going from what you posted in your last post, when you make an assignment you only want a single =, == is for comparison.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>

<script type="text/javascript">
window.onload = function() {
    var nice1 = document.getElementById("nice1");
    if(nice1.style.display=="inline")          
    {
        document.getElementById("nice2").style.display="none";
        document.getElementById("nice3").style.height="500px";
    }
    else if(nice1.style.display=="none")        
    {
        document.getElementById("nice2").style.display="inline";
        document.getElementById("nice3").style.height="800px";
    }
} 
</script>

</head>
<body>

<div id="nice1" style="display: inline;">text</div>

<div id="nice2">text</div>

<iframe id="nice3">text</iframe>

</body>
</html>

Open in new window


if that fixes it, please give the points to leakim971
0
 
leakim971PluritechnicianCommented:
== is to compare
= is to assign
there's a mistake, please locate the changes
window.onload = function() {
    var nice1 = document.getElementById("nice1");
    if(nice1.style.display=="inline")          
    {
        document.getElementById("nice2").style.display="none";
        document.getElementById("nice3").style.height="500px";
    }
    else if(nice1.style.display=="none")        
    {
        document.getElementById("nice2").style.display="inline";
        document.getElementById("nice3").style.height="800px";
    }
} 

Open in new window

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now