Get switch control value

Description

The following code shows how to get switch control value.

Example


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.6.2.js'></script>
<script type='text/javascript'
  src="http://code.jquery.com/mobile/1.0b1/jquery.mobile-1.0b1.js"></script>
<link rel="stylesheet" type="text/css"
  href="http://code.jquery.com/mobile/1.0b1/jquery.mobile-1.0b1.css">
<script type='text/javascript'>
$(function(){<!--   w w  w.  java 2s . c  o m-->
    var val = 'on';
    $('select#flag').change(function() {
        if(val!==$(this).val()){
            alert($(this).val());
        }
        val = $(this).val();
    });
});
</script>
</head>
<body>
  <div id="page" data-role="page">
    <select name="flag" id="flag" data-role="slider">
      <option value="off">OFF</option>
      <option value="on" selected="selected">ON</option>
    </select>
  </div>
</body>
</html>

Click to view the demo





















Home »
  jQuery Mobile »
    Example »




Button
Button Event
Button Icon
Button Text
Checkbox
Collapsible
Date
Dialog
Event
Footer
Form
Header
Icon
Input
Layout
Listview
Listview Divider
Listview Item
Loader
mobile_settings
Navbar
Page
Page Event
Popup
Radio
Select
Slider
Switch
Textarea
Theme