1

i have a list:

<select name="test" id="test">
<option value="1">about</option>
<option value="2">portfolio</option>
</select>

what i am trying to do is to load a different script inside a div #content depending on what option i choose. The script will load some rss content:

<div id="content">      
<script id="1" type="text/javascript" src="http://rss.bloople.net/?url=http%3A%2F%2Fwww.exploretalent.com%2Frss_cj.php%3Fpid%3D3087968%26file_xml%3Dcastings_new.xml&showtitle=false&type=js&id=1307038796890991"></script>
<script id="2" type="text/javascript" src="http://rss.bloople.net/?url=http%3A%2F%2Fwww.exploretalent.com%2Frss_cj.php%3Fpid%3D3087968%26file_xml%3Dcastings_new.xml&showtitle=false&type=js&id=1307038796890991"></script>
</div>

lets say if i select option 1 then a script with id 1 will load into page, if i select option 2 than the script with id 1 will unload and 2 will load

any ideas? thanks

3
  • manipulate with : api.jquery.com/jQuery.getScript Commented Jun 2, 2011 at 19:44
  • i think adding id to script is not a good idea. here is not mentioned that id is valid attribute for script Commented Jun 2, 2011 at 19:49
  • that doesn't really answer my question, does it? Commented Jun 2, 2011 at 19:50

3 Answers 3

1

You could use something like this

<select name="test" id="test">
    <option value=""></option>
    <option value="1">about</option>
    <option value="2">portfolio</option>
</select>

<div id="feed-1307038796890991"></div>

and the js

$(function(){
    var urls = [
        "http://rss.bloople.net/?url=http%3A%2F%2Fwww.exploretalent.com%2Frss_cj.php%3Fpid%3D3087968%26file_xml%3Dcastings_new.xml&showtitle=false&type=js&id=1307038796890991",
        "http://rss.bloople.net/?url=http%3A%2F%2Fwww.exploretalent.com%2Frss_cj.php%3Fpid%3D3087968%26file_xml%3Dcastings_new.xml&showtitle=false&type=js&id=1307038796890991"
        ];

    $("#test").change(function(){
        if ($(this).val() != ""){
            $.getScript(urls[$(this).val() - 1]);
        }
    })
})

Demo

Sign up to request clarification or add additional context in comments.

Comments

0

You could add a jQuery .click() event to the option elements, and have that click event call a jQuery .load() event.

It might look something like:

$('test').children()[0].click(function() {
  $('#resultDiv').load('yourLink.html');
});

1 Comment

well, my only problem is that i will have 50 <script id="...">. and i don't want to create 50 html pages
0

u Must see below dynamic javascript loader js library

headjs

OR

labjs

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.