Put javascript value in css style

Hi!

I have a three values i want to pass into the css style.

Se bold code...

....
if (WindowWidth>=1681)
  {
      //1920x1200
     swfHeight="66.250";
      swfWidth="93.750";
      swfHalfHeight=swfHeight/2  

  }
else if ((WindowWidth<=1680) && (WindowWidth>=1367))
  {
      //1680x1050
      swfHeight="50";
      swfWidth="70.750";
      swfHalfHeight=swfHeight/2  
  }
.......

Here is the css style

<style type="text/css">
      #distance {
            width:1px;
            height:50%;
            background-color:#cccccc;
            margin-bottom:-25em; /* half of container's height */
            float:left;
            }

      #container {
            margin:0 auto;
            position:relative; /* puts container in front of distance */
            text-align:left;
            height:50em;
            width:70.750em;
            clear:left;
            background-color:#cccccc;
            border:1px solid #000000;
            border-top-color:#000000;
            border-left-color:#000000;
            }

      #container div {
            font-size:80%;
            float:right;
            width:17em;
            margin-left:2em;
            }
</style>
LVL 1
myhrvoldAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

EyalCommented:
is this what you need?

getElementById('distance').style.marginBottom = ?
getElementById('container').style.height = swfHeight;
getElementById('container').style.width = swfWidth;

Open in new window

0
myhrvoldAuthor Commented:
Think so... how've do i use it and where do i put it?
0
EyalCommented:
right after the if else in the javascript
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

myhrvoldAuthor Commented:
Hi!

I cant get it to work.. What is wrong?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>TEST DYNAMIC SWF/DIV</title>
<script type="text/javascript">
<!--
       var WindowWidth;
       var WindowHeight;
       var swfHeight;
       var swfWidth;
       var swfHalfHeight;
      
       // Check window size start
       // ------------------------------------------------------------------------------
       // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
       if (typeof window.innerWidth != 'undefined')
       {
              WindowWidth = window.innerWidth,
              WindowHeight = window.innerHeight
       }
        
      // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
       else if (typeof document.documentElement != 'undefined'
             && typeof document.documentElement.clientWidth !=
             'undefined' && document.documentElement.clientWidth != 0)
       {
               WindowWidth = document.documentElement.clientWidth,
               WindowHeight = document.documentElement.clientHeight
       }
        
       // older versions of IE
       else
       {
               WindowWidth = document.getElementsByTagName('body')[0].clientWidth,
               WindowHeight = document.getElementsByTagName('body')[0].clientHeight
       }
       // ------------------------------------------------------------------------------
       // Check window size end

 
      // Check flash size start
      // ------------------------------------------------------------------------------  
      // give the flash correct size depend on window width..
      if (WindowWidth>=1681)
        {
            //1920x1200
            swfHeight="66.250";
            swfWidth="93.750";
            swfHalfHeight=swfHeight/2  
        }
      else if ((WindowWidth<=1680) && (WindowWidth>=1367))
        {
            //1680x1050
            swfHeight="50";
            swfWidth="70.750";
            swfHalfHeight=swfHeight/2  
        }
      else if ((WindowWidth<=1366) && (WindowWidth>=1281))
        {
            //1366x768
            swfHeight="42.375";
            swfWidth="60";
            swfHalfHeight=swfHeight/2  
        }
      else if ((WindowWidth<=1280) && (WindowWidth>=1025))
        {
            //1280x768
            swfHeight="31.813";
            swfWidth="45";
            swfHalfHeight=swfHeight/2  
        }
      else if ((WindowWidth<=1024) && (WindowWidth>=801))
        {
            //1024x768
            swfHeight="22.063";
            swfWidth="31.250";
            swfHalfHeight=swfHeight/2  
        }
      else if ((WindowWidth<=800) && (WindowWidth>=481))
        {
            //800x600
            swfHeight="22.063";
            swfWidth="31.250";
            swfHalfHeight=swfHeight/2  
        }
      else if ((WindowWidth<=640) && (WindowWidth>=481))
        {
            //640x480
            swfHeight="22.063";
            swfWidth="31.250";
            swfHalfHeight=swfHeight/2  
        }
      else
        {
            //480 -->
            swfHeight="22.063";
            swfWidth="31.250";
            swfHalfHeight=swfHeight/2  
        }
      // ------------------------------------------------------------------------------    
      // Check flash size end
      
      // Update the css style with given value.
      document.getElementById('distance').style.marginBottom = swfHalfHeight;
      document.getElementById('container').style.height = swfHeight;
      document.sgetElementById('container').style.width = swfWidth;
 //-->
</SCRIPT>

<style type="text/css">
      * {
            margin:0;
            padding:0;
            }

      html, body {
            height:100%;
            }

      body {
            background-color:#cccccc;
            color:#630;
            font:100.01%/1.4 sans-serif;
            text-align:center; /* horizontal centering for IE Win quirks */
            }

      #distance {
            width:1px;
            height:50%;
            background-color:#cccccc;
            margin-bottom:-25em; /* half of container's height */
            float:left;
            }

      #container {
            margin:0 auto;
            position:relative; /* puts container in front of distance */
            text-align:left;
            height:50em;
            width:70.750em;
            clear:left;
            background-color:#cccccc;
            border:1px solid #000000;
            border-top-color:#000000;
            border-left-color:#000000;
            }

      #container div {
            font-size:80%;
            float:right;
            width:17em;
            margin-left:2em;
            }
</style>
<style type="text/css">@import("iemac-center.css");</style>
</head>
<body>

<script type="text/javascript">
document.write('Vindu høyde er: '+WindowWidth+'<br>');
document.write('Vindu bredde er: '+WindowHeight+'<br>');
document.write('Flash høyde er: '+swfHeight+'<br>');
document.write('Flash bredde er: '+swfWidth+'<br>');
document.write('Flash margin er: '+swfHalfHeight+'<br>');
</script>

      <div id="distance"></div>
      <div id="container">
       Hello!
      </div>

</body>
</html>
0
EyalCommented:
well... you try to access the html elements before they are generated after the javascript

try this..

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>TEST DYNAMIC SWF/DIV</title>
<script type="text/javascript">
<!--

       var WindowWidth;
       var WindowHeight;
       var swfHeight;
       var swfWidth;
       var swfHalfHeight;

window.onload = function{      
       // Check window size start
       // ------------------------------------------------------------------------------
       // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
       if (typeof window.innerWidth != 'undefined')
       {
              WindowWidth = window.innerWidth,
              WindowHeight = window.innerHeight
       }
        
      // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
       else if (typeof document.documentElement != 'undefined'
             && typeof document.documentElement.clientWidth !=
             'undefined' && document.documentElement.clientWidth != 0)
       {
               WindowWidth = document.documentElement.clientWidth,
               WindowHeight = document.documentElement.clientHeight
       }
        
       // older versions of IE
       else
       {
               WindowWidth = document.getElementsByTagName('body')[0].clientWidth,
               WindowHeight = document.getElementsByTagName('body')[0].clientHeight
       }
       // ------------------------------------------------------------------------------
       // Check window size end

 
      // Check flash size start
      // ------------------------------------------------------------------------------  
      // give the flash correct size depend on window width..
      if (WindowWidth>=1681)
        {
            //1920x1200
            swfHeight="66.250";
            swfWidth="93.750";
            swfHalfHeight=swfHeight/2  
        }
      else if ((WindowWidth<=1680) && (WindowWidth>=1367))
        {
            //1680x1050
            swfHeight="50";
            swfWidth="70.750";
            swfHalfHeight=swfHeight/2  
        }
      else if ((WindowWidth<=1366) && (WindowWidth>=1281))
        {
            //1366x768
            swfHeight="42.375";
            swfWidth="60";
            swfHalfHeight=swfHeight/2  
        }
      else if ((WindowWidth<=1280) && (WindowWidth>=1025))
        {
            //1280x768
            swfHeight="31.813";
            swfWidth="45";
            swfHalfHeight=swfHeight/2  
        }
      else if ((WindowWidth<=1024) && (WindowWidth>=801))
        {
            //1024x768
            swfHeight="22.063";
            swfWidth="31.250";
            swfHalfHeight=swfHeight/2  
        }
      else if ((WindowWidth<=800) && (WindowWidth>=481))
        {
            //800x600
            swfHeight="22.063";
            swfWidth="31.250";
            swfHalfHeight=swfHeight/2  
        }
      else if ((WindowWidth<=640) && (WindowWidth>=481))
        {
            //640x480
            swfHeight="22.063";
            swfWidth="31.250";
            swfHalfHeight=swfHeight/2  
        }
      else
        {
            //480 -->
            swfHeight="22.063";
            swfWidth="31.250";
            swfHalfHeight=swfHeight/2  
        }
      // ------------------------------------------------------------------------------    
      // Check flash size end
      
      // Update the css style with given value.
      document.getElementById('distance').style.marginBottom = swfHalfHeight;
      document.getElementById('container').style.height = swfHeight;
      document.sgetElementById('container').style.width = swfWidth;

document.write('Vindu høyde er: '+WindowWidth+'<br>');
document.write('Vindu bredde er: '+WindowHeight+'<br>');
document.write('Flash høyde er: '+swfHeight+'<br>');
document.write('Flash bredde er: '+swfWidth+'<br>');
document.write('Flash margin er: '+swfHalfHeight+'<br>');

}
 //-->
</SCRIPT>

<style type="text/css">
      * {
            margin:0;
            padding:0;
            }

      html, body {
            height:100%;
            }

      body {
            background-color:#cccccc;
            color:#630;
            font:100.01%/1.4 sans-serif;
            text-align:center; /* horizontal centering for IE Win quirks */
            }

      #distance {
            width:1px;
            height:50%;
            background-color:#cccccc;
            margin-bottom:-25em; /* half of container's height */
            float:left;
            }

      #container {
            margin:0 auto;
            position:relative; /* puts container in front of distance */
            text-align:left;
            height:50em;
            width:70.750em;
            clear:left;
            background-color:#cccccc;
            border:1px solid #000000;
            border-top-color:#000000;
            border-left-color:#000000;
            }

      #container div {
            font-size:80%;
            float:right;
            width:17em;
            margin-left:2em;
            }
</style>
<style type="text/css">@import("iemac-center.css");</style>
</head>
<body>


      <div id="distance"></div>
      <div id="container">
       Hello!
      </div>

</body>
</html>

Open in new window

0
EyalCommented:
ooops.... missed something

instead of
window.onload = function {
write
window.onload = function () {
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
myhrvoldAuthor Commented:
Dont work....
0
Immanuel PhillipsUser Interface EngineerCommented:
And a small typo here:

// Update the css style with given value.
document.getElementById('distance').style.marginBottom = swfHalfHeight;
document.getElementById('container').style.height = swfHeight;
document.sgetElementById('container').style.width = swfWidth;

to

// Update the css style with given value.
document.getElementById('distance').style.marginBottom = swfHalfHeight;
document.getElementById('container').style.height = swfHeight;
document.getElementById('container').style.width = swfWidth;
0
Immanuel PhillipsUser Interface EngineerCommented:
Here you go.. Eyal just forgot the units (em)..

<script type="text/javascript">
<!--

       var WindowWidth;
       var WindowHeight;
       var swfHeight;
       var swfWidth;
       var swfHalfHeight;

window.onload = function() {      
       // Check window size start
       // ------------------------------------------------------------------------------
       // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
       if (typeof window.innerWidth != 'undefined')
       {
              WindowWidth = window.innerWidth,
              WindowHeight = window.innerHeight
       }
        
      // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
       else if (typeof document.documentElement != 'undefined'
             && typeof document.documentElement.clientWidth !=
             'undefined' && document.documentElement.clientWidth != 0)
       {
               WindowWidth = document.documentElement.clientWidth,
               WindowHeight = document.documentElement.clientHeight
       }
        
       // older versions of IE
       else
       {
               WindowWidth = document.getElementsByTagName('body')[0].clientWidth,
               WindowHeight = document.getElementsByTagName('body')[0].clientHeight
       }
       // ------------------------------------------------------------------------------
       // Check window size end

 
      // Check flash size start
      // ------------------------------------------------------------------------------  
      // give the flash correct size depend on window width..
      if (WindowWidth>=1681)
        {
            //1920x1200
            swfHeight = "66.250em";
            swfWidth = "93.750em";
        }
      else if ((WindowWidth<=1680) && (WindowWidth>=1367))
        {
            //1680x1050
            swfHeight = "50em";
            swfWidth = "70.750em";
            
        }
      else if ((WindowWidth<=1366) && (WindowWidth>=1281))
        {
            //1366x768
            swfHeight = "42.375em";
            swfWidth = "60em";
        }
      else if ((WindowWidth<=1280) && (WindowWidth>=1025))
        {
            //1280x768
            swfHeight = "31.813em";
            swfWidth = "45em";
        }
      else if ((WindowWidth<=1024) && (WindowWidth>=801))
        {
            //1024x768
            swfHeight = "22.063em";
            swfWidth = "31.250em";
        }
      else if ((WindowWidth<=800) && (WindowWidth>=640))
        {
            //800x600
            swfHeight = "22.063em";
            swfWidth = "31.250em";
        }
      else if ((WindowWidth<=640) && (WindowWidth>=481))
        {
            //640x480
            swfHeight = "22.063em";
            swfWidth = "31.250em";
        }
      else
        {
            //480 -->
            swfHeight = "22.063em";
            swfWidth = "31.250em";
        }
	
	swfHalfHeight = (parseFloat(swfHeight.substr(0, swfHeight.length - 2)) / 2) + "em";
      // ------------------------------------------------------------------------------    
      // Check flash size end
      
      // Update the css style with given value.
      document.getElementById('distance').style.marginBottom = swfHalfHeight;
      document.getElementById('container').style.height = swfHeight;
      document.getElementById('container').style.width = swfWidth;
}
 //-->
</SCRIPT>

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.