Firstable as I say convWt()
is not the same as convWT()
.
Then, you should never give the same id
to each of your input.
Try to make this like :
var inp = document.getElementById('inp');
var convGram = document.getElementById('convGram');
var convPound = document.getElementById('convPound');
var convMiliGram = document.getElementById('convMiliGram');
var convTon = document.getElementById('convTon');
var convOunce = document.getElementById('convOunce');
function convWt() {
var val = inp.value;
convGram.value = parseFloat(val * 1000);
convPound.value = parseFloat(val * 2.2046);
convMiliGram.value = parseFloat(val * 1000000);
convTon.value = parseFloat(val * 0.0011023);
convOunce.value = parseFloat(val * 35.274);
}
<center>
<h1>Weight Converter</h1>
</center>
<center>
<p>Welcome To Online Weight Converter</p>
</center>
<center><label>Weight In Kg:</label>
<form id="myForm">
<input id="inp" type="number" />
<input type="button" value="convert" onclick="convWt()" />
<table>
<tr>
<td>Weight In Grams:</td>
<td><input id="convGram" /></td>
</tr>
<tr>
<td>Weight In Pound</td>
<td><input id="convPound" /></td>
</tr>
<tr>
<td>MiliGram:</td>
<td><input type="text" id="convMiliGram" /></td>
</tr>
<tr>
<td>Us Ton:</td>
<td><input type="text" id="convTon" /></td>
</tr>
<tr>
<td>Ounces:</td>
<td><input id="convOunce"></td>
</tr>
<tr>
<td><input type="button" value="Rest Form" onclick="document.getElementById('myForm').reset()" /></td>
</tr>
</table>
</form>
<p><b/> You Can Press Reset Button For Another Conversion
</p>
</center>
It’s longer to write, yes, but it’s at best.
0
solved what is the error in javascripts i had already define the function but it could not find the defination