Reputation: 33
I'm working on an order form based on jQuery mobile, up until now I've been using http://demos.jquerymobile.com/1.4.2/forms/ for guidance (I'm not very good with JS but I'm learning). So far I have a form with a slider, a select (Yes/No), and a text box for the resulting calculation. All that's left is to take the slider value and multiple it by either a yes value or a no value and display it in the text box. For example, multiply by 8 if set to yes or 10 if set to no.
I've seen some examples of how to do this by converting a DIV into a basic slider but I haven't figured out a way to do it with the jQuery mobile slider. I'm still trying to figure it out but I'd appreciate any ideas.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" href="css/jquery.mobile-1.2.0.css" />
<link rel="stylesheet" href="css/jqm-docs.css"/>
<script src="js/jquery-1.7.1.min.js"></script>
<script src="js/jqm-docs.js"></script>
<script src="js/jquery.mobile-1.2.0.js"></script>
<style type="text/css">
body{background:none transparent}
</style>
</head>
<body>
<form action="redirector.php" method="POST" data-ajax="false" class="ui-body ui-body-a ui-corner-all">
<div data-role="fieldcontain"><input type="range" name="slots" id="slots" value="16" min="8" max="18" data-theme="a" data-track-theme="b" /></div>
<style type="text/css" media="screen">
.containing-element .ui-slider-switch { width: 9em; }
</style>
<div class="containing-element" style="">
<select name="type" id="flip-min" data-role="slider">
<option value="yes">yes</option>
<option value="no">no</option>
</select>
<div style="display: inline-block; vertical-align: top;">
<label for="amount" style="margin:6px 6px 0 0">Amount:</label>
<input style="display: inline-block; margin-top: 2px" name="amount" id="amount" value="" type="text">
</div>
</div>
<input type="submit" value="Submit" name="Submit_button"><input type="reset" value="Reset" name="Reset_button">
</form>
</body>
</html>
Upvotes: 1
Views: 1182
Reputation: 4108
Please try this one for sliding calculation
$("#flip-min").on("change", function () {
setAmount();
});
$("#slots").on("change", function () {
setAmount();
});
function setAmount(){
if ($("#flip-min").val() == "yes") {
var a = $("#slots").val();
$("#amount").val((a*10));
}
if ($("#flip-min").val() == "no") {
var a = $("#slots").val();
$("#amount").val((a*8));
}
}
fiddle demo here.
Upvotes: 3