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

    Join Date
    Sep 2012
    Posts
    1
    Rep Power
    0

    Variables in the HTML body?


    I have just started learning javascript and HTML, so this might sound really dumb since it might not even be possible. But I don't know, so I came here to ask.

    I have been following an online javascript course, and it taught me to create variables. Now, my question is, if I set a variable (created through a prompt), is it possible to call that variable back in the HTML body?

    Excuse me if this is a really stupid question - I'm just a beginner.

    Thanks in advance.
  2. #2
  3. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,317
    Rep Power
    7170
    Effectively yes, but you would do it by using JavaScript code to inject the value into the page rather than putting something in the page to pull in the value.

    For example, using jQuery:
    Code:
    <div id="content"></div>
    
    <script type="text/javascript">
    var myvalue = 123;
    
    $(document).ready(function() {
      $("#content").text(myvalue);
    });
    </script>
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around

IMN logo majestic logo threadwatch logo seochat tools logo