SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Aug 2006
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Changing SRC with javascript?

    Hello all,

    I am a newbie at javascript - but I wish to implement it in my PHP application.

    Basically, I'm trying to make a "chat-like" updater with javascript.

    html.html includes the following:
    Code:
    <html>
    <head>
    <script>
    var t;
    
    function getData () {
    	document.getElementById("dataStore").href = "test2.html";
    }
    
    function update (message) {
    	getData ();
    	document.getElementById("txt").innerHTML= message;
    	t = setTimeout ("update ()",1000);
    }
    </script>
    </head>
    <body onload="getData()">
    	<div id="txt">hello</div>
    	<script id="dataStore" type="text/javascript"></script>
    </body>
    </html>
    The file that it should get variables from is from test2.html, which is below:
    Code:
    var updateData = "hello!dasd";
    
    update (updateData);
    For this example, basically - I want javascript to change the "hello" in test.html to "hello!dasd" found in a variable in test2.html. This should keep asking for new updates from test2.html (which will be dynamic with php).

    If anyone could lend a hand, it'd be MUCH appreciated. I really don't know what I'm doing. =)

  2. #2
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First off, you cant load html file into a JavaScript file. You need to have an js extension.

    What you then need to do is to set the attribute src on the script tag. And one last thing, why do you need that timer for? Message parameter will be undefined when you call it from the timer


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
  •