#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Posts
    29
    Rep Power
    0

    Embed Javascript variable inside html


    I would like to define a variable inside of my javascript script section, and then, inside my html code, access the variable. For example: title=myJavascriptVariable, where myJavascriptVariable has been assigned in the script section. I believe I have seen this done.

    To clarify, I am not referring to href="javascript:functioncall()" or anything to do with events, such as onmouseover="functioncall()" which I already know work.

    I am referring rather to setting an attribute of an element, such as title, inside the html section, to a javascript variable.

    Thank you in advance.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2002
    Posts
    37
    Rep Power
    12
    best to use a hidden field

    <form name="hidden_field">
    <input type="hidden" name="something" value="whatever">
    </form>

    then with the javascript you can access this and also change it to what ever you want
    eg:
    var your_variable=document.hidden_field.something.value

    etc..

    that could be a start
  4. #3
  5. No Profile Picture
    Senior Citizen
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2001
    Location
    leftcoast
    Posts
    2,019
    Rep Power
    16
    About the minimum:

    var myTitle = 'foo';


    .....HTML.....
    <script>
    document.write('<div title="' + myTitle +'">);
    </script>
    .....HTML.....

    Too bad IE doesn't support JS entities...

IMN logo majestic logo threadwatch logo seochat tools logo