Javascript variables in html tags


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Javascript variables in html tags

Hybrid View

  1. #1
    Patrick Spence Guest

    Javascript variables in html tags

    Consider the following...

    <SCRIPT LANGUAGE="Javascript">

    var sFontFace = "arial narrow";
    var sFontSize = "8";

    </SCRIPT>

    <FONT FACE=&{sFontFace}; SIZE=&{sFontSize};>
    Hello World!
    </FONT>

    The above prints Hello World! in some other font other than "arial narrow".
    Ideas anyone? This "technique" was referenced on the Netscape site, but
    doesn't appear to work on MSIE. Is anyone *really* surprised about this? The
    goal here is to make a single assignment to variables that will contain the
    font faces and point size, then reference those variables w/in the html,
    making maintenance easier.



  2. #2
    Pushpa Guest

    Re: Javascript variables in html tags


    Hi Patrick,

    I have found that encapsulating your font preferences in Style sheets(CSS)
    makes life easier.
    With CSS, u can define a Class & then include it in ur HTML.
    For eg:-
    <html>
    <head>
    <LINK REL=STYLESHEET TYPE="text/css" SRC="/includes/Styles.css">
    <style type="text/css">
    <!--
    @import "Styles.css";
    .GreenBg
    {
    BACKGROUND-COLOR: #e0e0c2;
    COLOR: black;
    FONT-FAMILY: Verdana, Arial;
    FONT-SIZE: 8pt
    }

    -->
    </style>
    </head>
    <body>
    U can make ur text look green
    <table>
    <tr>
    <td Class="GreenBg">
    Hello World!!!
    </td>
    </tr>
    </table>

    </body>
    </html>


    "Patrick Spence" <patrick@pkspence.com> wrote:
    >Consider the following...
    >
    ><SCRIPT LANGUAGE="Javascript">
    >
    > var sFontFace = "arial narrow";
    > var sFontSize = "8";
    >
    ></SCRIPT>
    >
    ><FONT FACE=&{sFontFace}; SIZE=&{sFontSize};>
    > Hello World!
    ></FONT>
    >
    >The above prints Hello World! in some other font other than "arial narrow".
    >Ideas anyone? This "technique" was referenced on the Netscape site, but
    >doesn't appear to work on MSIE. Is anyone *really* surprised about this?

    The
    >goal here is to make a single assignment to variables that will contain

    the
    >font faces and point size, then reference those variables w/in the html,
    >making maintenance easier.
    >
    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center