I have a page with several tabs on it. When the user enters a value in a text input and then mashes a button, I want to replace the contents on a particular tab. I have this code (some of the details are elided to show just the pertinent parts/explain what I'm doing).
It works great the first time - the tab loads just fine; *subsequent* clicks of the button (after changing the text input value) has no effect, though. Why not? What must I do to force the tab to "refresh"? Something equivalent, perhaps, to a "Application.ProcessMessages()" in a desktop environment?
Here's the pertinent html:
<input type="text" name="inputText" id="inputText" placeholder="Enter something" autofocus style="display: inline-block;"
/>
<input type="button" name="inputButton" id="inputButton" value="Find" style="display: inline-block;" />
...and jQuery:
<script>
$.support.cors = true;
$(document).ready(function () {
$("#duckbilledPlatypusTabs").tabs({
});
$("#inputButton").click(function (e) {
var searchTerm = "";
if ($("#inputText").val() !== "") {
searchTerm = $("#inputText").val();
} else {
searchTerm = "jQuery";
}
//alert(searchTerm);
$("duckbilledPlatypusTab-YouTube").html("");
var urlYouTube = "http://gdata.youtube.com/feeds/api/videos?vq=" + searchTerm + "&max-
results=5&orderby=published&alt=json";
$.getJSON(urlYouTube, function (data) {
// Loop through each feed entry
$.each(data.feed.entry, function(i, item) {
// Get the URL for the video
var url = item.link[0].href;
// Get the title of the video
var title = item.title.$t;
// Get the first 10 characters of date video was published or: YYYY-MM-DD
var datepublished = item.published.$t.substring(0, 10);
// Get the author name
var author = item.author[0].name.$t;
// Get the thumbnail image for the video
var thumbnailURL = item.media$group.media$thumbnail[0].url;
// Construct the display for the video
var text =
"<br><a href='" + url + "'>" + title + "</a><br>" +
"Published: " + datepublished + " by " + author + "<br><br>" +
"<img src='" + thumbnailURL + "'><br>";
// Append the text string to the div for display
$("#duckbilledPlatypusTab-YouTube").append(text);
});
});
});
});
</script>