Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Posts
    362
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Putting variable in HTML

    Need to put a variable to substitute HTML data. Is it possible??

    Here the HTML that I have which is already part of a Javascript:
    <script>

    //Javascript stuff etc...
    <table bgcolor="#00ff00" border=0 cellpadding="0" cellspacing="0" width="100%" height="100%"
    align="left"><tr><td><a href="http://mypath/home.html">myurl</a></td></tr></table>;
    </script>
    How can I do this??

    var test = "<table bgcolor="#00ff00" border=0 cellpadding="0" cellspacing="0" width="100%"
    height="100%" align="left"><tr><td>"


    Here is how I want this variable to work.
    test<a href="http://mypath/home.html">myurl</a></td></tr></table>;

  • #2
    Regular Coder
    Join Date
    Jul 2002
    Location
    Western US
    Posts
    169
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Use can use the writeln().
    Pass it a variable, or string, and it will write it out in the document where you call it... So this script

    Code:
    <body>
    <script>
    myurl = 'http://mypath/home.html'
    test ='<table bgcolor="#00ff00" border=0 cellpadding="0" cellspacing="0" width="100%" height="100%" align="left"><tr><td><a href="' + myurl + '">myurl</a></td></tr></table>';
    document.writeln(test);
    </script>
    </body>
    would generate a green cell with the link in it. I also added a second variable just to see how that works. Make sure you don't get the ' and the " mixed up, or it will not parse correctly.

    ShriekForth


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •