-2

I am building a rss feed reader for my website , my goal is to display news headlines. I followed this tutorial(https://www.w3schools.com/php/php_ajax_rss_reader.asp). The code displays the rss feeds perfectly, but there is unwanted functionality; e.g:The user has to choose a feed from a select list before the feed will display. I want to keep the option to choose different feeds from the form but I would like the feed to display automatically without the need for the user to make a choice. Any help is greatly appreciated, Thanks

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css"></sxript>
 <script>
function showRSS(str) {
  if (str.length==0) {
document.getElementById("rssOutput").innerHTML="";
return;
  }
  if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
  } else {  // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.onreadystatechange=function() {
if (this.readyState==4 && this.status==200) {
  document.getElementById("rssOutput").innerHTML=this.responseText;
}
  }

<!-- begin snippet: js hide: false console: true babel: false -->
https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css
<form>
              <div class="form-group">
              <label>Select a News Feed</label>
<select class="form-control" onchange="showRSS(this.value)">
<option value="">Select an RSS-feed:</option>
<option value="One America News">One America News</option>
<option value="NBC">NBC News</option>
</select>
</form>
</div>
JustinG
  • 1
  • 3
  • 1
    Welcome JustingG, please provide your code so we can help you ! – Aref Ben Lazrek Aug 31 '17 at 05:17
  • The code is here->https://www.w3schools.com/php/php_ajax_rss_reader.asp . Im trying to modify the code to display the rss feed automatically without the need for the user to make a choice, but I would like to keep the form as an option. – JustinG Aug 31 '17 at 15:24

1 Answers1

-1

Without having all the code in the snippet above it is hard to write a proper code snippet as an answer. However you can try adding:

showRSS("Google");

right after the function called showRSS and see if that works.

There are better ways to do this, including an IIFE (you can look it up), but that should work for now

joshua miller
  • 1,686
  • 1
  • 13
  • 22
  • I have tried your suggestion, but its not working. I tried using console.log("google") and that doesnt give me my desired effect. Im new to javascript and I need more help with this. I would like a default feed to load with the page and a select list form to allow users to select a choice from a list of feeds. Here is my php -> – JustinG Sep 21 '17 at 14:25