Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Oct 2008
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Rss Feeds and SRC

    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:
    Code:
    <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%3DUTF-8%26nolr%3D1%26output%3Drss%26ned%3D%3AePkh8BM9E2IRYipIFeJ2YrU0MTQw9bhyUlUIzVqgitQcbJbD7P3FBlTwi401Jz85EUgzF6UmAwCycxKf&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.

  • #2
    ess
    ess is offline
    Regular Coder
    Join Date
    Oct 2006
    Location
    United Kingdom
    Posts
    866
    Thanks
    7
    Thanked 30 Times in 29 Posts
    Assuming that you only have one script tag declared within the html document, you can try and use the following...inside a function perhaps:

    PHP Code:
    var src window.document.getElementsByTagName("script")[0];
    src.setAttribute("src""url reference here"); 
    Cheers
    ~E

  • #3
    New to the CF scene
    Join Date
    Oct 2008
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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!


    Code:
    <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%3DUTF-8%26nolr%3D1%26output%3Drss%26ned%3D%3AePkh8BM9E2IRYipIFeJ2YrU0MTQw9bhyUlUIzVqgitQcbJbD7P3FBlTwi401Jz85EUgzF6UmAwCycxKf&chan=n&num=5&desc=0&date=n&targ=n"); 
     }
    </script>
    
    </head>
    
    <body>
    <script language="JavaScript" type="text/javascript" src="changer()"></script>
    </body>
    </html>

  • #4
    ess
    ess is offline
    Regular Coder
    Join Date
    Oct 2006
    Location
    United Kingdom
    Posts
    866
    Thanks
    7
    Thanked 30 Times in 29 Posts
    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.

    PHP Code:
    <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

  • Users who have thanked ess for this post:

    chuang21 (10-06-2008)

  • #5
    New to the CF scene
    Join Date
    Oct 2008
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks!!!!!!!!!!!! Your awesome, thanks a lot!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •