I have form with two text inputs.
<form>
1<input type="text" id="test" name="test" />
2<input type="text" id="test2" name="test" />
</form>
<div id="dimensions"></div>
<div id="texte"></div>
When a user types values into these fields, jQuery automatically calculates the ratio and draws a rectangular div with width and height typed in form, but only up to 200x200 px.
My problem is that when I type, for example width=3 and height=100, my div is greater then max dimensions and I can't find where my mistake is.
$(document).ready(function () {
$("#test, #test2").keyup(function () {
var width = $("#test").val();
var height = $("#test2").val();
var max = 200;
var min = 20;
var ratio;
if(width>=height){
ratio = max / width;
width = ratio * width;
height = height * ratio;
} else {
ratio = max / height;
height = ratio * height;
width = width * ratio;
};
$("#dimensions").html(width + " x " + height);
$("#texte").css({ "width":width + "px", "height":height + "px" });
});
});