CdnGal
10-13-2002, 02:01 AM
HI all...
I have to do a silly little program where you enter a number, select one of three options from a drop down list to convert the number (ie. feet to meters)..then place the newly converted value in a text box. My coding works, and if I use a window.alert, the value appears there..but I need it to appear in a text box. When I run it, the new value does appear in the correct text box..but only for a flash second. What in the world am I doing wrong?
Here's some of the coding. (I've also attached the file if it will help) Thanks for any help!
function convertValue() {
var x=(document.frm1.fromValue.value)* (document.frm1.conversion.value);
(document.frm1.toValue.value=x);
}
</script>
</head>
<body>
<h3>Various Conversions</h3>
<h4>Enter a number to be converted and select one of the three options</h4>
<form name="frm1">
<table>
<tr>
<td><b>From Value</b></td>
<td></td>
<td><b>To Value</b></td>
</tr>
<tr>
<td>
<input type="text" name="fromValue" value="" size="15">
</td>
<td>
<select name="conversion">
<option value="0.4047">Acres to Hectares</option>
<option value=".305">Feet to Meters</option>
<option value="4.54">Imp Gallons to Litres</option>
</select>
</td>
<td><input type="text" name="toValue" value=""size="15"><br>
</td>
</tr>
<tr>
<td>
<input type="submit" value="Convert" onClick=convertValue()>
</td>
</tr>
</table>
</form>
I have to do a silly little program where you enter a number, select one of three options from a drop down list to convert the number (ie. feet to meters)..then place the newly converted value in a text box. My coding works, and if I use a window.alert, the value appears there..but I need it to appear in a text box. When I run it, the new value does appear in the correct text box..but only for a flash second. What in the world am I doing wrong?
Here's some of the coding. (I've also attached the file if it will help) Thanks for any help!
function convertValue() {
var x=(document.frm1.fromValue.value)* (document.frm1.conversion.value);
(document.frm1.toValue.value=x);
}
</script>
</head>
<body>
<h3>Various Conversions</h3>
<h4>Enter a number to be converted and select one of the three options</h4>
<form name="frm1">
<table>
<tr>
<td><b>From Value</b></td>
<td></td>
<td><b>To Value</b></td>
</tr>
<tr>
<td>
<input type="text" name="fromValue" value="" size="15">
</td>
<td>
<select name="conversion">
<option value="0.4047">Acres to Hectares</option>
<option value=".305">Feet to Meters</option>
<option value="4.54">Imp Gallons to Litres</option>
</select>
</td>
<td><input type="text" name="toValue" value=""size="15"><br>
</td>
</tr>
<tr>
<td>
<input type="submit" value="Convert" onClick=convertValue()>
</td>
</tr>
</table>
</form>