0

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>
2
Contributors
3
Replies
6
Views
7 Years
Discussion Span
Last Post by rouse
0

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>
1

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

Edited by Airshow: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.