Capturing Form Data and submitting to an Ajax call
I am just getting started here and have this working fine for me. It retrieves 4 items from a flicker feed. (Look familiar?)
- <!DOCTYPE = html>
- <html lang="en">
- <head>
- <meta charset="UTF-8" />
- <title>My Test Page</title>
- <script type = "text/javascript" src = "jquery.js"></script>
- <div id=rating></div>
- </head>
- <body>
- <h1>Flicker feed</h1>
- <div id="images"></div>
- <script>
- // Start after document has loaded)
- $(function(){
- RunAjax()
- });
- // This is what you run
- function RunAjax()
- {
- var tag = "cat"
- $.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?tags="+ tag + "&tagmode=any&format=json&jsoncallback=?",
- function(data)
- {$.each(data.items, function(i,item)
- {$("<img/>").attr("src", item.media.m).appendTo("#images");
- if ( i == 3 ) return false;
- });
- });
- };
- </script>
- </body>
- </html>
What I would like to do is to have my variable, "tag" be the result of a form submission on the page.
My form can be as simple as the following:
- <form id="flickerform">
- <fieldset>
- <legend>Flicker Search Feed</legend>
-
- <label>Parameter:</label>
- <input type="text" id="tags" name="tags" />
-
- <button type="submit">Search</button>
-
- </fieldset>
- </form>
So when one clicks on the Submit button, I want it to take take the value of my tags form field and pass it to my RunAjax function and return the data corresponding to that tag value.
I am not clear on how to make that request within the form action and method. Any help would be greatly appreciated.