I want to write some javascript where
  • The user inputs a search term into a text box

  • The user presses the submit button & parses the user-input to a function

  • Data is displayed on the page

  • The user can enter a second seach term & presses the same button

  • the page is refreshed and the function runs again with the user input & displays different data

(i hope that makes sense)

I've written the following code:

//called when the refresh button is pressed
function refreshPage(){

//called when the search button is pressed
function changeText(){
searchTerm = document.getElementById('searchTerms').value;
$(document).ready (function(){
var url = "http://search.twitter.com/search.json?q="
+ searchTerm+ "&rpp=15&callback=?";

The code works but is clunky & requires 2 buttons. It seems the nested function "$(document).ready (function(){" will not run a second time. The page needs to be refreshed and then changeText() called again.