Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: script activated from drop down box

  1. #1
    Join Date
    Jul 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post script activated from drop down box

    hey guys this may be really simple

    i have a drop down box on my webpage and i need it to run a script when the value changes

    but the script it runs depends on the value of the selected item in the drop down box

    any idea on how i could do this with minimal coding.... or not what ever is easy lol


    thanks in advance

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    <select onchange="doSomething(this.value);">
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Jul 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    ooo never thought of that thanks

    how do i then get the scritpt to load another script from a js file , i know how to do the onload do-dah , but how can i get it to do it from a function :S am at a lil loss here

    thanks again in advance

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    <script type="text/javascript">
      var loadScript = (function() {
        var head = document.getElementsByTagName("head")[0];
        return function(url) {
          var s = document.createElement("script");
          s.type = "text/javascript";
          s.src = url;
          return head.appendChild(s);
        };
      })();
    </script>
    
    <select onchange="loadScript(this.value);">
      <option value="scripts/fish.js">Fish</option>
      <option value="cabbage.js">Cabbage</option>
      <option value="http://www.otherserver.com/somescript.js">Remote Script</option>
    </select>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Jul 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    am having a lil trouble implementing this :s

    it doesnt seem to be running my scritps when the value changes

    anything you can thing of

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    What's the code you're using?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Jul 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Code:
    <script type="text/javascript">
      var loadScript = (function() {
        var head = document.getElementsByTagName("head")[0];
        return function(url) {
          var s = document.createElement("script");
          s.type = "text/javascript";
          s.src = url;
          return head.appendChild(s);
        };
      })();
    </script>
    <body onload="numbers();winners();date()">
    
    
    <select onchange="loadScript(this.value);">
      <option value="archive/06 July 07 onewish.js">06 July 07</option>
      <option value="archive/13 July 07 onewish.js">13 July 07</option>
     </select>
    basically what you gave me with the body onload i was using when i was calling the functions from a known script , ie one single script not a selection

  8. #8
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Hmm... maybe if we escape the URL. There's a memory leak in IE in that code too, I just realised.
    Code:
    function loadScript(url) {
      var s = document.createElement("script");
      s.type = "text/javascript";
      s.src = encodeURI(url);
      return document.getElementsByTagName("head")[0].appendChild(s);
    };
    Note that since the document has already loaded, document.write() and similar things won't work, if you've used any of those.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  9. #9
    Join Date
    Jul 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    doesnt seem to work


    i am using
    PHP Code:
    document.getElementById('data1').innerHTML 'name' 
    to change large amount of data, this code is generated by a program i wrote , if you know of another way of doing this then i am open to sugetions

    thanks again in advance
    Last edited by martyn1987; 07-18-2007 at 10:56 AM.

  10. #10
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    "Doesn't work" is a poor description of the problem. What does it do? What doesn't it do? What errors do you get?

    innerHTML is bad (use the DOM methods instead), but that's not the problem in this case -- unless you're using XHTML it should still work.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •