1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Rep Power

    Use Javascript variable in html

    Hi, I'm using this code to determine the window width and height of a visitor to my page, but after I have the values os winW and winH, how can I use them in a tag for setting a table width and height?

    Basically I have a table on my page that I would like to fit the window properly when someone visits my page, I'm just not sure how to use the values in my html after I got them from a javascript. Thanks


    Code to find window height and width :

    var winW = 630, winH = 460;

    if (parseInt(navigator.appVersion)>3) {
    if (navigator.appName=="Netscape") {
    winW = window.innerWidth;
    winH = window.innerHeight;
    if (navigator.appName.indexOf("Microsoft")!=-1) {
    winW = document.body.offsetWidth;
    winH = document.body.offsetHeight;

    "Window width = "+winW+"<br>"
    +"Window height = "+winH
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2002
    Rep Power
    I am pretty new to web coding myself, but I would assign the values to two hidden inputs (one for width and one for height) and then integrate PHP into your HTML for the tables and call those variables for the W and H. I know it would work, but im sure there is a better way to do it.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Waterloo, ON
    Rep Power
    put this where you want your code for the table height and width to go:

    <script language="JavaScript">
    document.write("<table width=\"" + winW + "\" .... ")

    and so on.

IMN logo majestic logo threadwatch logo seochat tools logo