Sunday, November 27, 2011

jQuery Mobile: get max and min of Slider using attr()

jQuery Mobile: get max and min of Slider using attr()

To get max and min setting of Slider, we can use:
$("#slider").attr("min");
$("#slider").attr("max");


jQuery Mobile: get max and min of Slider using attr()

example:
<!DOCTYPE html>
<html>
<head>
<meta name = "viewport" content = "width = device-width, height = device-height" />
<title>jQuery Mobile: Slider</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/latest/jquery.mobile.css" />
<script src="http://code.jquery.com/jquery.min.js"></script>
<script src="http://code.jquery.com/mobile/latest/jquery.mobile.min.js"></script>
</head>
<body>

<div data-role="page" id="home">
<div data-role="header">
<h1>Slider</h1>
</div>
<div data-role="content">
<p>jQuery Mobile: Slider</p>
<div data-role="fieldcontain">
<label for="slider">Slider:</label>
<input type="range" name="slider" id="slider" value="0" min="0" max="100" />
<input type="button" value="Read Slider" onclick="button_clicked()" />
<input type="button" value="Set Slider to 0." onclick="minbutton_clicked()" />
<input type="button" value="Set Slider to half." onclick="halfbutton_clicked()" />
<input type="button" value="Set Slider to 100." onclick="maxbutton_clicked()" />


</div>
</div>
<div data-role="footer">
<h4><a href="http://mobile-web-app.blogspot.com/">http://mobile-web-app.blogspot.com/</a></h4>
</div>
</div>

<div data-role="page" id="dialog">
<div data-role="header">
<h1>mobile-web-app</h1>
</div>
<div data-role="content">
<p>It's a Dialog</p>
</div>
<div data-role="footer">
<h4><a href="http://mobile-web-app.blogspot.com/">http://mobile-web-app.blogspot.com/</a></h4>
</div>
</div>

<script>
function button_clicked(){
var SliderValue = $("#slider").val();
alert("Slider value = " + SliderValue);
}

function minbutton_clicked(){
var min = $("#slider").attr("min");
$("#slider").val(min).slider("refresh");
}

function halfbutton_clicked(){
var min = $("#slider").attr("min");
var max = $("#slider").attr("max");
var half = (min + max)/2;
$("#slider").val(half).slider("refresh");
}

function maxbutton_clicked(){
var max = $("#slider").attr("max");
$("#slider").val(max).slider("refresh");
}
</script>

</body>
</html>

jQuery Mobile: Set value of Slider using JavaScript code dynamically

jQuery Mobile: Set value of Slider using JavaScript code dynamically

To set value of Slider using JavaScript code by calling $("#slider").val(0).slider("refresh"). Remember to include ".slider("refresh")", otherwise the slide may not be updated to the new value.

jQuery Mobile: Set value of Slider using JavaScript code dynamically

example:
<!DOCTYPE html>
<html>
<head>
<meta name = "viewport" content = "width = device-width, height = device-height" />
<title>jQuery Mobile: Slider</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/latest/jquery.mobile.css" />
<script src="http://code.jquery.com/jquery.min.js"></script>
<script src="http://code.jquery.com/mobile/latest/jquery.mobile.min.js"></script>
</head>
<body>

<div data-role="page" id="home">
<div data-role="header">
<h1>Slider</h1>
</div>
<div data-role="content">
<p>Hello ALL</p>
<p>jQuery Mobile: Slider</p>
<div data-role="fieldcontain">
<label for="slider">Slider:</label>
<input type="range" name="slider" id="slider" value="0" min="0" max="100" />
<input type="button" value="Read Slider" onclick="button_clicked()" />
<input type="button" value="Set Slider to 0." onclick="minbutton_clicked()" />
<input type="button" value="Set Slider to 100." onclick="maxbutton_clicked()" />
</div>
</div>
<div data-role="footer">
<h4><a href="http://mobile-web-app.blogspot.com/">http://mobile-web-app.blogspot.com/</a></h4>
</div>
</div>

<div data-role="page" id="dialog">
<div data-role="header">
<h1>mobile-web-app</h1>
</div>
<div data-role="content">
<p>It's a Dialog</p>
</div>
<div data-role="footer">
<h4><a href="http://mobile-web-app.blogspot.com/">http://mobile-web-app.blogspot.com/</a></h4>
</div>
</div>

<script>
function button_clicked(){
var SliderValue = $("#slider").val();
alert("Slider value = " + SliderValue);
}

function minbutton_clicked(){
$("#slider").val(0).slider("refresh");
}

function maxbutton_clicked(){
$("#slider").val(100).slider("refresh");
}
</script>

</body>
</html>



next:
- jQuery Mobile: get max and min of Slider using attr()

jQuery Mobile: Read value of Slider

To get value of Slider in jQuery Mobile, we can read $("#slider").val().

jQuery Mobile: Read value of Slider

example:
<!DOCTYPE html>
<html>
<head>
<meta name = "viewport" content = "width = device-width, height = device-height" />
<title>jQuery Mobile: Slider</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/latest/jquery.mobile.css" />
<script src="http://code.jquery.com/jquery.min.js"></script>
<script src="http://code.jquery.com/mobile/latest/jquery.mobile.min.js"></script>
</head>
<body>

<div data-role="page" id="home">
<div data-role="header">
<h1>Slider</h1>
</div>
<div data-role="content">
<p>Hello ALL</p>
<p>jQuery Mobile: Slider</p>
<div data-role="fieldcontain">
<label for="slider">Slider:</label>
<input type="range" name="slider" id="slider" value="0" min="0" max="100" />
<input type="button" value="Read Slider" onclick="button_clicked()" />
</div>
</div>
<div data-role="footer">
<h4><a href="http://mobile-web-app.blogspot.com/">http://mobile-web-app.blogspot.com/</a></h4>
</div>
</div>

<div data-role="page" id="dialog">
<div data-role="header">
<h1>mobile-web-app</h1>
</div>
<div data-role="content">
<p>It's a Dialog</p>
</div>
<div data-role="footer">
<h4><a href="http://mobile-web-app.blogspot.com/">http://mobile-web-app.blogspot.com/</a></h4>
</div>
</div>

<script>
function button_clicked(){
var SliderValue = $("#slider").val();
alert("Slider value = " + SliderValue);
}
</script>

</body>
</html>



next:
- jQuery Mobile: Set value of Slider using JavaScript code dynamically

Saturday, November 26, 2011

jQuery Mobile: Slider

jQuery Mobile: Slider
<!DOCTYPE html>
<html>
<head>
<meta name = "viewport" content = "width = device-width, height = device-height" />
<title>jQuery Mobile: Slider</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/latest/jquery.mobile.css" />
<script src="http://code.jquery.com/jquery.min.js"></script>
<script src="http://code.jquery.com/mobile/latest/jquery.mobile.min.js"></script>
</head>
<body>

<div data-role="page" id="home">
<div data-role="header">
<h1>Slider</h1>
</div>
<div data-role="content">
<p>Hello ALL</p>
<p>jQuery Mobile: Slider</p>
<div data-role="fieldcontain">
<label for="slider">Slider:</label>
<input type="range" name="slider" id="slider" value="0" min="0" max="100" />
</div>
</div>
<div data-role="footer">
<h4><a href="http://mobile-web-app.blogspot.com/">http://mobile-web-app.blogspot.com/</a></h4>
</div>
</div>

<div data-role="page" id="dialog">
<div data-role="header">
<h1>mobile-web-app</h1>
</div>
<div data-role="content">
<p>It's a Dialog</p>
</div>
<div data-role="footer">
<h4><a href="http://mobile-web-app.blogspot.com/">http://mobile-web-app.blogspot.com/</a></h4>
</div>
</div>

</body>
</html>


next:
- jQuery Mobile: Read value of Slider

Related:
- Implement Slider using jQuery
- Implement Slider using jQuery UI

Sunday, November 13, 2011

Flip Toggle Switches

Example of Flip Toggle Switches:

Flip Toggle Switches

<!DOCTYPE html>
<html>
<head>
<meta name = "viewport" content = "width = device-width, height = device-height" />
<title>jQuery Mobile: Flip toggle switches</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/latest/jquery.mobile.css" />
<script src="http://code.jquery.com/jquery.min.js"></script>
<script src="http://code.jquery.com/mobile/latest/jquery.mobile.min.js"></script>
</head>
<body>

<div data-role="page" id="home">
<div data-role="header">
<h1>Flip toggle switches</h1>
</div>
<div data-role="content">
<p>Hello ALL</p>
<p>jQuery Mobile: Flip toggle switches</p>
<div data-role="fieldcontain">
<label for="myoption">Flip toggle switches:</label>
<select name="myoption" id="myoption" data-role="slider">
<option value="off">Off</option>
<option value="on">On</option>
</select>
</div>
</div>
<div data-role="footer">
<h4><a href="http://mobile-web-app.blogspot.com/">http://mobile-web-app.blogspot.com/</a></h4>
</div>
</div>

<div data-role="page" id="dialog">
<div data-role="header">
<h1>mobile-web-app</h1>
</div>
<div data-role="content">
<p>It's a Dialog</p>
</div>
<div data-role="footer">
<h4><a href="http://mobile-web-app.blogspot.com/">http://mobile-web-app.blogspot.com/</a></h4>
</div>
</div>
<script>
function button_clicked(){
alert("Button Clicked!");
}
</script>
</body>
</html>

Tuesday, November 8, 2011

viewport for Mobile device

If you try the examples in former post, you will get difference appearance on difference browser, even on the same device. We haven't take care about the viewport for mobile device. You can override the default viewport by including a viewport meta tag in the <head> section of your page.

example:
<!DOCTYPE html>
<html>
<head>
<meta name = "viewport" content = "width = device-width, height = device-height" />
<title>jQuery Mobile: Dialog</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/latest/jquery.mobile.css" />
<script src="http://code.jquery.com/jquery.min.js"></script>
<script src="http://code.jquery.com/mobile/latest/jquery.mobile.min.js"></script>
</head>
<body>

<div data-role="page" id="home">
<div data-role="header">
<h1>Open Dialog</h1>
</div>
<div data-role="content">
<p>Hello ALL</p>
<p>jQuery Mobile: Dialog</p>
<a href="#dialog" data-rel="dialog" data-transition="pop">Open Dialog</a>
</div>
<div data-role="footer">
<h4><a href="http://mobile-web-app.blogspot.com/">http://mobile-web-app.blogspot.com/</a></h4>
</div>
</div>

<div data-role="page" id="dialog">
<div data-role="header">
<h1>mobile-web-app</h1>
</div>
<div data-role="content">
<p>It's a Dialog</p>
<input type="button" value="Close Dialog" onclick="button_clicked()" />
</div>
<div data-role="footer">
<h4><a href="http://mobile-web-app.blogspot.com/">http://mobile-web-app.blogspot.com/</a></h4>
</div>
</div>
<script>
function button_clicked(){
$('.ui-dialog').dialog ('close');
}
</script>
</body>
</html>



Android default browser
Firefox on Android
Opera Mobile on Android

Friday, November 4, 2011

jQuery Mobile: Manually close dialog using JavaScript code

To close dialog using JavaScript, by following code:
$('.ui-dialog').dialog ('close');

jQuery Mobile: Manually close dialog using JavaScript code

<!DOCTYPE html>
<html>
<head>
<title>jQuery Mobile: Dialog</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/latest/jquery.mobile.css" />
<script src="http://code.jquery.com/jquery.min.js"></script>
<script src="http://code.jquery.com/mobile/latest/jquery.mobile.min.js"></script>
</head>
<body>

<div data-role="page" id="home">
<div data-role="header">
<h1>Open Dialog</h1>
</div>
<div data-role="content">
<p>Hello ALL</p>
<p>jQuery Mobile: Dialog</p>
<a href="#dialog" data-rel="dialog" data-transition="pop">Open Dialog</a>
</div>
<div data-role="footer">
<h4><a href="http://mobile-web-app.blogspot.com/">http://mobile-web-app.blogspot.com/</a></h4>
</div>
</div>

<div data-role="page" id="dialog">
<div data-role="header">
<h1>mobile-web-app</h1>
</div>
<div data-role="content">
<p>It's a Dialog</p>
<input type="button" value="Close Dialog" onclick="button_clicked()" />
</div>
<div data-role="footer">
<h4><a href="http://mobile-web-app.blogspot.com/">http://mobile-web-app.blogspot.com/</a></h4>
</div>
</div>
<script>
function button_clicked(){
$('.ui-dialog').dialog ('close');
}
</script>
</body>
</html>




Thursday, November 3, 2011

jQuery Mobile: Simple Button and onclick event

jQuery Mobile: Simple Button and onclick event
Example code:
<!DOCTYPE html>
<html>
<head>
<title>jQuery Mobile: Button</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/latest/jquery.mobile.css" />
<script src="http://code.jquery.com/jquery.min.js"></script>
<script src="http://code.jquery.com/mobile/latest/jquery.mobile.min.js"></script>
</head>
<body>

<div data-role="page" id="home">
<div data-role="header">
<h1>Button</h1>
</div>
<div data-role="content">
<p>Hello ALL</p>
<p>jQuery Mobile: Button</p>
<input type="button" value="Simple Button" onclick="button_clicked()" />
</div>
<div data-role="footer">
<h4><a href="http://mobile-web-app.blogspot.com/">http://mobile-web-app.blogspot.com/</a></h4>
</div>
</div>

<div data-role="page" id="dialog">
<div data-role="header">
<h1>mobile-web-app</h1>
</div>
<div data-role="content">
<p>It's a Dialog</p>
</div>
<div data-role="footer">
<h4><a href="http://mobile-web-app.blogspot.com/">http://mobile-web-app.blogspot.com/</a></h4>
</div>
</div>
<script>
function button_clicked(){
alert("Button Clicked!");
}
</script>
</body>
</html>