Previous Example-|-Next Example-|-Return to Chapter Listing

Example 5.14:
Type Conversion--Subtracting Strings and Numerics


Click this button to see the value in the sVariable2 variable, calculated by adding a string variable to a numeric variable:

Now click here to see what happens when you subtract a numeric value from a string:



This is the script we used. First we placed this in the HEAD: <SCRIPT LANGUAGE="JAVASCRIPT"> <!-- var sVariable1 = "555" var sVariable2 = sVariable1 + 10 var sVariable3 = sVariable1 - 10 //--> </SCRIPT> Then we created these buttons: <form> <input type="button" name="VariableButton" value="sVariable2: String + Numeric" onclick="alert(sVariable2)"><P> <input type="button" name="VariableButton" value="sVariable3: String - Numeric" onclick="alert(sVariable3)"> </form>
Previous Example-|-Next Example-|-Return to Chapter Listing