Results 1 to 3 of 3

Thread: Html variable insert?

  1. #1
    Join Date
    Apr 2005
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Html variable insert?

    This should be easy for someone that knows what there doing.

    want to create a file called

    country.js
    <body>
    <script language="javascript">
    <!--
    var albania = 4;
    //-->
    </script>
    </body>

    and then pass the "4" to many different html pages

    <script language="javascript">document.write(albania);</script>

    but it's not working.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    You might show us what you've tried. For something simple like that, the sending page can have this on it:

    HTML Code:
    <a href="nextpage.htm?var1=albania">Click here to go Albanian Style!</a>
    Then on the recieving page have:

    Code:
    <script type="text/javascript">
    var text = unescape(window.location.href);
    function delineate(str) {
    theleft = str.indexOf("=") + 1;
    theright = str.indexOf("&");
    return(str.substring(theleft, str.length));
    }
    var sentInfo=delineate(text)
    
    document.write(sentInfo);
    
    </script>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by HomeStar
    [...] want to create a file called country.js
    <body>
    <script language="javascript">
    <!--
    var albania = 4;
    //-->
    </script>
    </body>
    Perhaps I'm reading too much into the above, but a script should never contain bare markup. The content of country.js should just be

    Code:
    var albania = 4;
    included in the head element with

    HTML Code:
    <script type="text/javascript" src="country.js"></script>
    and then pass the "4" to many different html pages
    If you're looking to include the same content in several different documents, you might want to look into server-side include (SSI) support.



    Quote Originally Posted by jscheuer1
    function delineate(str) {
    theleft = str.indexOf("=") + 1;
    theright = str.indexOf("&");
    return(str.substring(theleft, str.length));
    }
    I really do wish you'd stop posting that particular function. Please appreciate how badly written, and inflexible, it is. It may be fine in situations where only one name/value pair exists in the query string, but that is hardly a robust, future-proof solution.

    Mike

Bookmarks

Posting Permissions

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