Book Image

Mastering jQuery UI

By : Vijay Joshi
Book Image

Mastering jQuery UI

By: Vijay Joshi

Overview of this book

Table of Contents (19 chapters)
Mastering jQuery UI
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating a weather widget


For the weather widget, first we will create the dropdown with names of cities, then we will add the event handler for its change event. Write the following code inside the setupWeather method to create a dropdown and binding event handler:

var cities = ['Delhi, India', 'London,UK', 'New York,USA', 'Tokyo,Japan'];
var strCity = '<option value="0">select a city</option>';
$(cities).each(function(i, item)
{
  strCity+= '<option value="' + item + '">' + item + '</option>';
});
$('#selCity').html(strCity);

$('#selCity').change(function()
{
  var selection = $(this).val();
  if(selection == 0)
  {
    return;
  }
  dashboard.displayWeather(selection);
  
});

To create a cities dropdown, we created an array called cities that contains some city names around the world. Then we iterate in this array and create dropdown options with each city name and insert it into the dropdown with id selCity.

Next we bind the event handler for change event on the...