0

I'm trying to create a button that takes a subject you've typed in and pulls the relevant tweets using the Twitter Search API.

I've seen something similar with the jTwitter plugin, but I'm not sure on how to do it myself, and can't seem to find any documentation on it.

Here's the jQuery:

twitterUrl = "http://search.twitter.com/search.json?"+ q +"&rpp=1500&page=2&result_type=recent&callback=?";
       twitterList = $( "<ul />" );
       twitterFunction = function( data ) {
             $.each( data.results, function( i, item ) {
                   $( "<li />", { "text" : item.text } )
                        .appendTo( twitterList );
                   });
             $( "#twit" ).fadeOut( "fast", function(){
                   $( this ).empty()
                        .append( twitterList )
                        .fadeIn( "slow" );            
                   });
             };
$.getJSON( twitterUrl, twitterFunction );

And the HTML:

<article>
        <form>
            <input type="text" id="subject" name="q" placeholder="subject..." >
            <input type="button" id="start" value="start" >
        </form>
        <div id="twit"></div>
</article>

And a working jsFiddle.

Thanks for your help.

Ryan
  • 69
  • 2
  • 10

2 Answers2

1

Check the implementation @ http://jsfiddle.net/Jayendra/reVy7/10/

Customize the results handling.

Jayendra
  • 52,349
  • 4
  • 80
  • 90
  • Great, thank you. I should've known the value would be inside of q= instead of replacing it. Is there a way to get it to work if you type in the subject and press enter as well as clicking start? – Ryan Oct 01 '11 at 12:34
  • you can handle it via keyup and checking enter code as 13 ... http://stackoverflow.com/questions/155188/trigger-button-click-with-javascript-on-enter-key-in-text-box – Jayendra Oct 01 '11 at 17:26
  • For some reason it doesn't work when I try adding that jQuery snippet. The text in the input field disappears when I hit enter. Does it have to be implemented within the function for the JSON call? http://jsfiddle.net/RyanNeil/q7jUB/12/ – Ryan Oct 02 '11 at 10:02
0

I'll suggest you to use jQuery Twitter Search Plugin

xkeshav
  • 53,360
  • 44
  • 177
  • 245