JSFiddle - React, Tailwind, and code Playground
HTML
<div class="form">
<label for="units">Units:</label>
<input type="text" name="units" id="units" class="required digits" />
</div>
<div class="form">
<label for="from">Convert From:</label>
<select name="from" id="from">
<option value="from">-Select an Option-</option>
<option value="degC" selected="selected">Celcius</option>
</select>
</div>
<div class="form">
<label for="to">Convert Into:</label>
<select name="to" id="to">
<option value="to">-Select an Option-</option>
<option value="degF" selected="selected">Fahrenheit</option>
</select>
</div>
<div class="form">
<input id="btnConvert" type="submit" name="submit" value="Convert!" />
</div>
<div class="form">
<label> Result: </label>
<input id="result" type="text" name="res" value="" />
</div>
JavaScript
function Convert(from, to, units, res){
this.from = from;
this.to = to;
this.units = units;
this.res = res;
}
Convert.prototype.convertThem = function(){
var result = "invalid input";
var input = parseInt(this.units.val());
var f = this.from.val();
var t = this.to.val()
if(!isNaN(input)) {
if(f == "degC"){
if(t == "degF"){
result = input * 1.8 + 32;
}
}
}
console.log('Parsed input is', input, "and result is", result);
this.res.val(result);
return result;
}
var calcTempTest = new Convert($("#from"), $("#to"), $("#units"), $("#result"));
$("#btnConvert").click(calcTempTest.convertThem.bind(calcTempTest));