javascript - How to have a range to two input boxes where it will be divided after... -
i have 2 input fields automatically divides first input second one.
first input field:
<input type="text" name="myname1" id="1" value="1000.00" onkeyup="getvalues(1)" size="10">
second input field:
<input type="text" name="myname2" id="2" value="26" onkeyup="getvalues(2)" size="10">
output:
<input type="text" id="main" name="myoutput" size="5" value=38.46>
and script:
<script language="javascript"> function getvalues(val){ var numval1=parsefloat(document.getelementbyid("1").value,10); var numval2=parsefloat(document.getelementbyid("2").value,10); var totalvalue = numval1 / numval2; document.getelementbyid("main").value = totalvalue.tofixed(2); } </script>
how can add min/max range both input fields range accepted on first input field 200-1000, , second input field 1-26. alert cool if value not within specified range.
thanks!!!
do simple interval-bound check:
function getvalues(val){ var numval1=parsefloat(document.getelementbyid("1").value,10); var numval2=parsefloat(document.getelementbyid("2").value,10); var totalvalue = numval1 / numval2; if(numval1 >= 200 && numval1 <= 1000){ document.getelementbyid("1").style.bordercolor='red'; }else{ document.getelementbyid("1").style.bordercolor=''; } if(numval2>= 1&& numval2 <= 26){ document.getelementbyid("2").style.bordercolor='red'; }else{ document.getelementbyid("2").style.bordercolor=''; } document.getelementbyid("main").value = totalvalue.tofixed(2); }
Comments
Post a Comment