In HTML all input text come in as a text value. When we need to perform some calculation on the text value we need to first convert them to a system numeric value. Once it is converted, we can then perform arithmetic function on it. Here's how to it in Javascript:

In this example we would use the function parseInt to convert the value. Afterward you could use the function isNaN to check if the input is of type numeric.

<script type="text/javascript">

    function CalcAspect() {

 

        var strOldWidth = parseInt(document.getElementById('oldWidth').value);

        var strNewWidth = parseInt(document.getElementById('newWidth').value);

        var strOldHeight = parseInt(document.getElementById('oldHeight').value);

        var strNewHeight = parseInt(document.getElementById('newHeight').value);

 

        if (isNaN(strOldWidth)) {

            alert(strOldWidth);

        }

        else {

            alert(strOldWidth);

        }           

    }       

</script>

The above example uses parseInt to convert the value.

parseInt(document.getElementById('oldWidth').value);


 
* iOS Development * OS X * Product Review