Build jQuery UI Spinner - Overflow in JavaScript

Description

The following code shows how to build jQuery UI Spinner - Overflow.

Example


<!-- Revised from demo code on http://jqueryui.com/ -->
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Spinner - Overflow</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
<link type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css" rel="stylesheet" />
<!-- ww w. ja va 2  s.  c  o  m-->
<script>
$(function() {
$( "#spinner" ).spinner({
spin: function( event, ui ) {
if ( ui.value > 10 ) {
$( this ).spinner( "value", -10 );
return false;
} else if ( ui.value < -10 ) {
$( this ).spinner( "value", 10 );
return false;
}
}
});
});
</script>
</head>
<body>

<p>
<label for="spinner">Select a value:</label>
<input id="spinner" name="value" />
</p>

<div class="demo-description">
<p>
Overflowing spinner restricted to a range of -10 to 10.
For anything above 10, it'll overflow to -10, and the other way round.
</p>
</div>
</body>
</html>

Click to view the demo

The code above generates the following result.

Build jQuery UI Spinner - Overflow in JavaScript
Home »
  Javascript Tutorial »
    jQuery UI »
      Spinner
Javascript Tutorial Spinner
Build jQuery UI Spinner - Currency in JavaS...
Build jQuery UI Spinner - Decimal in JavaSc...
Build jQuery UI Spinner - Default functiona...
Build jQuery UI Spinner - Map in JavaScript
Build jQuery UI Spinner - Overflow in JavaS...
Build jQuery UI Spinner - Time in JavaScrip...