SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast Scottie2Hottie7's Avatar
    Join Date
    Jul 2004
    Location
    England
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Using JavaScript To Load ... JavaScript ... Fails

    I Have A Script Which Loads A php (js) file Every time A Button Is Clicked.

    HTML Code:
    <script language="JavaScript">
    function DoChat() {
    var now = new Date();
    var thecode = '<scr' + 'ipt language="JavaScript" src="Code/LoginValid.php?username=' + escape(MyForm.username.value) + '&password=' + escape(MyForm.password.value) + '&time=' + now.getTime() + '&rand=' + (Math.round(Math.random() * 100000) % 10000) + '"></' + 'scr' + 'ipt>'
    var thecode2 = String(thecode);
    alert(scriptloader.innerHTML)
    scriptloader.innerHTML = thecode2;
    alert(scriptloader.innerHTML)
    }
    </script>
    As You Can See, It Has Two Alerts For Debugging Purposses.
    The First Time You Execute The Script, It Alerts Whatever The Content Was Already. Then It Alerts A Blank Alert Box
    The Second Time You Execute The Script. It Pops Up Two Empty Alert Boxes.
    All The Time, Code/LoginValid.php is NOT EXECUTED.

    How Can I Fix This?

    Please!!!.

  2. #2
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What is scriptloader?
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  3. #3
    SitePoint Zealot codescribbler's Avatar
    Join Date
    Nov 2004
    Location
    New York, NY
    Posts
    141
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've never tried this sort of thing before, but I would look into whether the fact that you have set the language of the php file to 'javascript' would be causing it to fail?

    Also, I don't know if you can include a php file with html tags.

    What are you ultimately trying to do, exactly?

    Edited: ok, found this link: http://academ.hvcc.edu/~kantopet/php...ent=php+basics

    I didn't know you could do that. However, I do see that language here is set to php. try that?
    Last edited by codescribbler; Jun 4, 2005 at 16:44. Reason: found some info, understand more

  4. #4
    &#083;itePoint Aficionado JVLB's Avatar
    Join Date
    Jan 2002
    Location
    N 44 56.537' W 123 3.683'
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Using innerHTML to load an external script is not reliable. You need to use DOM methods to create a new script element, then set its src attribute, and finally append the new element to the document.


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
  •