In: Computer Science
I am having a hard time getting my an output after putting in the second set of functions and I was hoping to be able to have the results from the functions be rounded to 2 decimal places.
<html>
<head>
<title>Length Conversion</title>
<script language='JavaScript' type='text/JavaScript'>
<!--
function validate(type) {
if(document.my_form.textinput.value=='')
{
alert('Fill the Input box before submitting');
return false;
}else{
if(type=="to_feet"){
var res=3.2808*document.my_form.textinput.value;
var unit=" feet";
}else{
var res=0.3048*document.my_form.textinput.value;
var unit=" meter";
}
document.getElementById("result").innerHTML=res.toFixed(2) +
unit;
return false;
}
}
function validate1(type) {
if(document.my_form.textinput.value=='')
{
alert('Fill the Input box before submitting');
return false;
}else{
if(type=="to_pounds"){
var res=document.my_form1.textinput1.value/2.205;
var unit=" pounds";
}else{
var res=2.205*document.my_form1.textinput.value;
var unit=" kilograms";
}
document.getElementById("result1").innerHTML=res.toFixed(2) +
unit;
return false;
}
//-->
</script>
</head>
<body>
<p> This form allows you to convert between different systems
, enter the known length and click on the desired
conversion.</p>
<form name='my_form' action='' method='post'
onSubmit='return validate();'>
Input :<input type=text name=textinput size=10>
<input type=button value='Convert to Feet'
onClick=validate('to_feet');>
<input type=button value='Convert to Meter'
onClick=validate('to_meter');>
</form>
<div id=result></div>
<hr>
<p1> This portion will allow you to convert between two
different systems of pounds and kilograms. </p1>
<form name='my_form1' action='' method='post'
onSubmit='return
validate1();'>
Input:<input type=text name=textinput1 size=10>
<input type=button value='Convert to Pounds'
onClick=validate1('to_pounds');>
<input type=button value='Convert to Kilograms'
onClick=validate1('to_kilograms');>
</form>
<div1 id=result1></div>
</body>
</html>
deserves thumbs up :)
<html>
<head>
<title>Length Conversion</title>
<script language='JavaScript' type='text/JavaScript'>
function validate(type){
if(document.getElementById("inp1").value=='')
{
alert('Fill the Input box before submitting');
return false;
}
else{
if(type=="to_feet"){
var
res=3.2808*parseFloat(document.getElementById("inp1").value);
var unit=" feet";
}else{
var
res=0.3048*parseFloat(document.getElementById("inp1").value);
var unit=" meter";
}
document.getElementById("result").innerHTML=res.toFixed(2) +
unit;
return false;
}
}
function validate1(type) {
if(document.getElementById("inp2").value=='')
{
alert('Fill the Input box before submitting');
return false;
}else{
if(type=="to_pounds"){
var
res=parseFloat(document.getElementById("inp2").value)/2.205;
var unit=" pounds";
}else{
var
res=2.205*parseFloat(document.getElementById("inp2").value);
var unit=" kilograms";
}
document.getElementById("result1").innerHTML=res.toFixed(2) +
unit;
return false;
}
}
</script>
</head>
<body>
<p> This form allows you to convert between different systems
, enter the known length and click on the desired
conversion.</p>
<form name='my_form' action='' method='post'
onSubmit='return validate();'>
Input :<input id="inp1" type=text name=textinput
size=10>
<input type=button value='Convert to Feet'
onClick=validate('to_feet');>
<input type=button value='Convert to Meter'
onClick=validate('to_meter');>
</form>
<div id=result></div>
<hr>
<p1> This portion will allow you to convert between two
different systems of pounds and kilograms. </p1>
<form name='my_form1' action='' method='post'
onSubmit='return validate1();'>
Input:<input id="inp2" type=text name=textinput1
size=10>
<input type=button value='Convert to Pounds'
onClick=validate1('to_pounds');>
<input type=button value='Convert to Kilograms'
onClick=validate1('to_kilograms');>
</form>
<div1 id=result1></div>
</body>
</html>