I have to validate input field on the specific way:
This value must be divisible by proof value (can be integer or float). If there is an integer as result – OK, if the result is float – find the next smalles and biggest that can be divisible by this proof value.
I have following code at the Moment:
$("#calc").click( function(){
var rlaenge = $("#rlaenge").val(); // is allways an integer
var zEins = $("#zEins").val();
var zZwei = $("#zZwei").val();
var typeMath = <?php $_SESSION['typeMath']; ?>; // can be integer or float
var erg = (parseFloat(rlaenge) - ((( parseFloat(zEins) + parseFloat(zZwei) ) / 2) * parseFloat(typeMath) )) / 2;
var rlaengeCheck = rlaenge/typeMath;
if (/^[0-9 ]+$/.test(rlaengeCheck)) {
$("#result").value(erg);
} else {
//here the situation with findig off next biggest/next smallest
}
});
I don’t have any Idea how to build such one issue with JavaScript.
I will be very grateful for any help with this case.
Alex.
well you can do this so:
OLD
use
MathmethodsThe
floor()method rounds a number DOWNWARDS to the nearest integer, and returns the resultThe
ceil()method rounds a number UPWARDS to the nearest integer, and returns the result.then check devision then ++, — the value if check not passed