Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

anything simpler than document.write() ?

  • 09-08-2004 12:19PM
    #1
    Registered Users, Registered Users 2 Posts: 1,281 ✭✭✭


    i'm porting over a college project ( current version can be viewed online at http://www.thegalwaysky.com/starcheck/ ) from ASP to a pure client-side JavaScript application.

    i was wondering if there is a simpler way of writing variables within the body of an html document than every time having to use:

    <script language="JavaScript1.5">
    document.write(myVar);
    </script>

    asp and php have useful shortcuts for writing the values of variables within the html body, eg. <%= myVar %> for ASP. can something similar be done with JavaScript ?

    cheers,
    jAH


Comments

  • Registered Users, Registered Users 2 Posts: 8,452 ✭✭✭Time Magazine


    Try

    var d.w = document.write;

    then try d.w.(myVar);

    Alternatively make a function, e.g. x(myVar), whose command is simply to document.write(). So you get <script>x(myVar)</script> each time. It's a little easier.


  • Registered Users, Registered Users 2 Posts: 1,281 ✭✭✭jArgHA


    cheers banana,

    the x(myVar) function sounds good although i thought there may have been a shortcut for getting rid of the <script> tags also (as in ASP/PHP). ps nice website you've got there.

    grma,
    jAH


  • Registered Users, Registered Users 2 Posts: 1,967 ✭✭✭Dun


    The javascript tags/source can't be removed because the browser runs the javascript on the client computer, whereas PHP/ASP is processed on the server. Angry Banana's is probably the neatest way of handling what you're doing.


Advertisement