...

View Full Version : Rss Feeds and SRC



chuang21
10-03-2008, 05:47 PM
Hi yall, this forum is great! I have a question, and i am a bit of a newbie so please bear with me...

I am trying to display an rss feed in one of my portlets on an employee portal we have. I'd like to make this rss feed dynamic depending on what the user selects from a drop down...

I got a javascript i found online which displays the rss feed, but I was wondering if it was possible to alter the src part so that it can change depending on what company is selected.

Example this script shows pfizer's newsfeed:

<script language="JavaScript" src="http://itde.vccs.edu/rss2js/feed2js.php?src=http%3A%2F%2Fnews.google.com%2Fnews%3Fhl%3Den%26tab%3Dwn%26q%3Dpfizer%2Binc%26ie%3DU TF-8%26nolr%3D1%26output%3Drss%26ned%3D%3AePkh8BM9E2IRYipIFeJ2YrU0MTQw9bhyUlUIzVqgitQcbJbD7P3FBlTwi401J z85EUgzF6UmAwCycxKf&chan=n&num=5&desc=0&date=n&targ=n" type="text/javascript"></script>


Is there a way to change the SRC location and make it dynamic so that it can change? For instance in the code above there is a section for "pfizer%2Binc" if this part in the src is changed to another company name it shows that companies rss feed.

ess
10-03-2008, 09:23 PM
Assuming that you only have one script tag declared within the html document, you can try and use the following...inside a function perhaps:


var src = window.document.getElementsByTagName("script")[0];
src.setAttribute("src", "url reference here");

Cheers
~E

chuang21
10-03-2008, 11:02 PM
Hi Thank you so much for your response. I tried it with the function called changer() where all it does is assign src a url, but nothing happens... I assigned src="changer()" was that wrong? Thanks again!




<html>
<head>
<script type="text/javascript">
function changer(){
var src = window.document.getElementsByTagName("script")[0];
src.setAttribute("src", "http://itde.vccs.edu/rss2js/feed2js.php?src=http%3A%2F%2Fnews.google.com%2Fnews%3Fhl%3Den%26tab%3Dwn%26q%3Dpfizer%2Binc%26ie%3DU TF-8%26nolr%3D1%26output%3Drss%26ned%3D%3AePkh8BM9E2IRYipIFeJ2YrU0MTQw9bhyUlUIzVqgitQcbJbD7P3FBlTwi401J z85EUgzF6UmAwCycxKf&chan=n&num=5&desc=0&date=n&targ=n");
}
</script>

</head>

<body>
<script language="JavaScript" type="text/javascript" src="changer()"></script>
</body>
</html>

ess
10-04-2008, 11:03 AM
Well...you need to call the function when you wish to change the source of the script tag.

Ok...I have created a simple example which changes an image source when a user selects an image name from a drop down list. I know, you are after a script tag...but the dynamics of this script work similarly and you will only need to change few things for your purposes.


<html>
<head><title>Somepage</title>
<script type="text/javascript">
function changer(valueIn){
var src = window.document.getElementsByTagName("img")[0];
src.setAttribute("src", valueIn.value);
}

</script>
</head>
<body>
<p>
Please select from the drop down menu...and wait for a bit for the image to load.
Since the images are loacated on different servers, the load time will depend
on how fast your interet connection is.
</p>
<p>
<select onchange="javascript: changer(this);">
<option selected="yes">------</option>
<option value ="http://www.cssnz.org/flower.jpg">Flower1</option>
<option value ="http://www.botany.com/img/plants/dictionary-plants-flowers.jpg">Flower2</option>
</select>
</p>

<p>
<img src="http://www.countryflower.com/Country_Flower_Home_Pic.jpg" title="flowers" />
</p>

</body>
</html>

Hope this helps...if not, let's know.

Cheers
~E

chuang21
10-06-2008, 05:22 PM
Thanks!!!!!!!!!!!! Your awesome, thanks a lot!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum