Results 1 to 8 of 8

Thread: Loading JS in the same id place..PLZ HELP

  1. #1
    Join Date
    Jan 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Loading JS in the same id place..PLZ HELP

    Dear all

    I searched all the net about this Question but I could not find any script for it or any solution...
    or if that can be or not ...

    I need to click on button to load external js .
    then to click on another button and load an external js in the same place of the first one

    Please click to see the example :
    http://www.creativelink-sy.com/example/test.html

    Please inform me as soon as possible

    Thanks in advance

  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

    First of all, you cannot use the document.write() method after a page is loaded without overwriting the entire page. Second, if all you want to do is change the background color of a table, there are much easier ways. With the type of layout your page has, a simple:

    Code:
    <input type="button" onclick="document.getElementsByTagName('table')[1].style.backgroundColor='blue'" value="Make Blue">
    Would do the trick, if you give the red table an id, it would be even easier.
    - John
    ________________________

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

  3. #3
    Join Date
    Jan 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks :
    But I don't want to change colors...
    I want to change the contain of the external js, the external js may contains tables - data - text - another design page ---elc...........
    So the example what I need is to change the js with another one ..
    Regards

  4. #4
    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

    Scripts can be swapped using AJAX and perhaps even using the method you have, changing the script tag's src attribute, I've never tested the latter method. However, the new script cannot contain just anything. As I just explained, the document.write() method is out, unless you do want the page overwritten. Also, anything in the new script that would normally execute as a page loads and/or on page load, will not execute simply because the script replaces one that did execute when the page was originally loaded. With these facts in mind, there is very little to be gained in swapping scripts. What exactly did you hope to accomplish?
    - John
    ________________________

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

  5. #5
    Join Date
    Jan 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks buddy
    Well , I exactly want to load exrenal js .the same as ifarme html pages.
    but I don't want to use iframe...
    So If there is any idea that I can load pages on click using extrenal js that's will helps me instead of using iframes.
    Do u have any other idea?
    Thanks

  6. #6
    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

    I'm still not clear on what, if anything concrete, you want to do. Try looking over the AJAX scripts offered here to see if any are close. I also found one script specifically for loading javascripts:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    <script type="text/javascript">
    
    var JSAdd;
    
    function AddJS(name){
     head=document.getElementsByTagName('HEAD')[0];
     // next line removes the previously addid External JavaScript
     if (JSAdd){ head.removeChild(JSAdd); }
     JSAdd=document.createElement('SCRIPT');
     JSAdd.type='text/javascript';
     JSAdd.src=name;
     head.appendChild(JSAdd);
    }
    
    function Test(){
     alert('An External JavaScript\nhas not been Added');
    }
    
    </script>
    
    </head>
    
    <body>
    <form name="add_query">
    <input type="button" name="" value="Add JS fred.js"  onclick="AddJS('fred.js');" /><br />
    <input type="button" name="" value="Add JS tom.js"  onclick="AddJS('tom.js');" /><br />
    <input type="button" name="" value="Test"  onclick="Test();" /><br />
    </form>
    </body>
    
    </html>
    Here are the two external files:

    fred.js
    _____________

    Code:
    function Test(){
     alert('External JavaScript fred.js\nhas been Added');
    }
    _____________

    tom.js
    _____________

    Code:
    function Test(){
     alert('External JavaScript tom.js\nhas been Added');
    }
    _____________
    - John
    ________________________

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

  7. #7
    Join Date
    Jan 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    yeah thanks
    I already have this script .. it invoke function only ...
    anyhow... thanks alot buddy

  8. #8
    Join Date
    Jan 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    WOW :::: Thanks a lot buddy WOW WOW WOW that's it .. really I have asked alot of programmers outthere surfing the net in many forums.. no one answered me ... I have found it in AJAX scripts yes you are the best you are really the best thanks a lot..................................10000000 1000 times

    I love that....
    Thanks

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
  •