Web Analytics Made Easy -
StatCounter Variables - CodingForum

Announcement

Collapse
No announcement yet.

Variables

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Variables

    Hi there.

    I was wondering if anyone could help me with the use of variables in scripting.

    As an example, I have some images I have created which I am using in <a href ...></a>, but until I've finished designing things I won't know how many buttons there'll be or how big I'll want them. Therefore I want the ability to change the width and height values of the image in my HTML file without having to change them here, there and everywhere as I do know.

    I've tried:

    height_of_button = 31
    width_of_button = 118

    within <script language="javascript"></script>

    but when I attempt

    <img src ... width = height_of_button>

    or

    <img src ... width = &height_of_button>

    the image doesn't even get rendered.

    Can somebody please tell me how I use variables both:

    (1) within the given HTML file
    (2) globally amongst various HTML files linked together as a site

    Thank you very much.

    Russ.

  • #2
    <script language="javascript">

    function loader() {

    width_of_button = 118
    height_of_button = 31

    document.getElementById("imag1").style.width = width_of_button;
    document.getElementById("imag1").style.height = height_of_button;

    }

    </script>

    <body onload="loader()">

    <img src="" id="imag1">

    Comment


    • #3
      Variables

      Thanks for that x_goose_x.

      Russell.

      Comment

      Working...
      X