546 views

Javascript Change String to Integer

we simply use parseInt() function to convert string into integer:

Example1:

parseInt(”34px”);

  1. Output: 34

Example2:

Size:

  1. <script type="text/javascript">function incre()
  2. {
  3. var increase = 10;
  4. wid = parseInt(document.getElementById(’style_class’).style.width);
  5. document.getElementById(’style_class’).style.width = wid + increase;
  6. }</script>
  7. <table border="0">
  8. <tbody>
  9. <tr>
  10. <td id="style_class" style="width: 80px; height: 50px; background-color: red;"></td>
  11. </tr>
  12. </tbody></table>
  13. <strong>Size:</strong>
  14.  
  15. <input onclick="getElementById(’style_class’).style.width=’100′" name="botton" type="button" value="Size to 100" /> <input onclick="getElementById(’style_class’).style.width=’120′" name="botton" type="button" value="Size to 120" /> <input onclick="incre()" name="botton" type="button" value="Increase by +10" />

Post a Comment

You must be logged in to post a comment.