To prevent repetitive code, we normally use Javascript function to save us time from rewriting code. You could put all common javascript in a .js file or in a script tag. This function can be call anywhere in the class file or in a HTML page.

Example:

<script type="text/javascript">


function ExampleFunction(var1, var2, var3, ..., varXYZ)

{

   alert('hello ' + var1);

}


function CalcAspect()

{

   alert('hello ');

}



<table border="1px" style="border: 1px solid #000; padding: 2px;">

    <tr>

        <td></td>

        <td><strong>Original Value</strong></td>

        <td><strong>New Value</strong></td>

    </tr>

    <tr>

        <td>Width</td>

        <td><input type="text" id="oldWidth" name="oldWidth" /></td>

        <td><input type="text" id="newWidth" name="newWidth"/></td>

    </tr>

    <tr>

        <td>Height</td>

        <td><input type="text" id="oldHeight" name="oldHeight" /></td>

        <td><input type="text" id="newHeight" name="newHeight"/></td>

    </tr>

    <tr>

        <td colspan="3" align="right"><input type="button" value="Calculate" onclick="CalcAspect()" /></td>           

    </tr>

</table>

You can place the call in any element event. For example to call the function on the onclick event do this: onclick="CalcAspect()".


 
* iOS Development * OS X * Product Review