I have these two javascript functions and wish to "merge" them into one. I will be adding a few more of these converting functions later on and would like to keep it simple and cleaner than just duplicating the functions.
<!--Convert kg in pnd-->
<script type="text/javascript">
function init(){
document.getElementById('kg').onmouseup=function() {
if(isNaN(this.value)) {
alert('numbers only!!');
document.getElementById('kg').value='';
document.getElementById('pnd').value='';
return;
}
document.getElementById('pnd').value=(this.value*2.2046).toFixed(1);
}
}
if(window.addEventListener){
window.addEventListener('load',init,false);
}
else {
if(window.attachEvent){
window.attachEvent('onload',init);
}
}
</script>
<!--Convert cm in feet-->
<script type="text/javascript">
function start(){
document.getElementById('hauteur_cm').onmouseup=function() {
if(isNaN(this.value)) {
alert('numbers only!!');
document.getElementById('hauteur_cm').value='';
document.getElementById('hauteur_pieds').value='';
return;
}
document.getElementById('hauteur_pieds').value=(this.value*0.03280839895).toFixed(1);
}
}
if(window.addEventListener){
window.addEventListener('load',start,false);
}
else {
if(window.attachEvent){
window.attachEvent('onload',start);
}
}
</script>
Thanks for the help