I would like to run the javascript code in between the script tag on a button press, but the code runs as the page load. Please point out what I am doing incorrectly.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="html/html; charset=UTF-8" />
        <link rel="stylesheet" type="text/css" href="css/reset.css" />
        <link rel="stylesheet" type="text/css" href="css/local.css" />
        <script type="text/javascript" src="js/jquery.js"></script>
        <script type="text/javascript" src="js/jquery.jgfeed.js"></script>
        <!--
        Inline Javascript
        -->
        <script type="text/javascript">
              $.jGFeed(
                'http://feedproxy.google.com/nettuts',
                function(feeds){
                    // Check for errors
                    if(!feeds){
                        // there was an error
                        return false;
                    }
                    // do whatever you want with feeds here
                    $('#message').append('Hello World<br />');
                    for(var i=0; i<feeds.entries.length; i++){
                        var entry = feeds.entries[i];
                        // Entry title
                        entry.title;
                        $('#message').append(entry.title + '<br />');
                        $('#message').append(entry.link + '<br />');
                        $('#message').append(entry.author + '<br />');
                        $('#message').append(entry.publishedDate + '<br />');
                        $('#message').append(entry.contentSnippet + '<br />');
                    }}, 10);
        </script>
    </head>
    <body>
        <div id="wrapper">
            <div id="instruction">
                <input type="button" value="Start RSS" onClick="$.jGFeed()"/>
                <div id="content">
                    <div id="message">
                    </div>
                </div>
            </div>
        </div>
    </body>
</html>

Recommended Answers

All 3 Replies

Given a button with an id of start, I thought this is what I should be doing with this script.

<input type="button" id="start" value="Start RSS" />
<script type="text/javascript">
            $("#start").click(function(){
              $.jGFeed(
                'http://feedproxy.google.com/nettuts',
                function(feeds){
                    // Check for errors
                    if(!feeds){
                        // there was an error
                        return false;
                    }
                    // do whatever you want with feeds here
                    $('#message').append('Hello World<br />');
                    for(var i=0; i<feeds.entries.length; i++){
                        var entry = feeds.entries[i];
                        // Entry title
                        entry.title;
                        $('#message').append(entry.title + '<br />');
                        $('#message').append(entry.link + '<br />');
                        $('#message').append(entry.author + '<br />');
                        $('#message').append(entry.publishedDate + '<br />');
                        $('#message').append(entry.contentSnippet + '<br />');
                    }}, 10);
                });
        </script>

Rouse,

Please, STOP CODING AND DO SOME READING - for about a day.

You need to look at the jquery documentation and some examples. In particular you need to learn how to frame your code in a structure of the form:

$(document).ready(function() {
   // put all your jQuery goodness in here.
 });

Until you can do that just about nothing will work.

I suggest you start here.

Good luck.

Airshow

Thanks for your help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.