I'm trying to create a simple px to em converter that automatically calculates the values when one of the input fields is changed. I've got the code to calculate the values but it won't update when a value is changed.
Heres the HTML
<body>
<h1>PX to EM converter</h1>
<div id="base">
<h2>Enter a base pixel size</h2>
<input id="baseSize" value="16">
<p>px</p>
</div>
<div id="px">
<input id="pxInput" value="16">
<p>px</p>
<div id="emOutput2"></div>
</div>
<p>em</p>
<div id="Em">
<input id="emInput" value="1">
<p>em</p>
<div id="pxOutput2">
</div>
<p>px</p>
</div>
</body>
And the js
$(document).ready(function() {
var baseSize2 = $('#baseSize').val();
var pxInput = $('#pxInput').val();
var emInput = $('#emInput').val();
var emOutput = function() {
return pxInput / baseSize2;
};
var pxOutput = function() {
return emInput * baseSize2;
};
$('#baseSize').attr('value', baseSize2);
$('#pxInput').attr('value', pxInput);
$('#emInput').attr('value', emInput);
$('#pxOutput2').html(pxOutput);
$('#emOutput2').html(emOutput);
});
Any help would be most appreciated