Javascript Change String to Integer

197 views

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" />



« Use Of Style Attribute in javascript (use of css) Taking Value Of Attributes inside HTML Tags Using preg_match_all (eg. img src=”") »
Posted on Tuesday, April 21st, 2009 at 3:33 pm under Javascript, Tips and tricks | RSS 2.0 Feed

Post Comment

You must be logged in to post a comment.



ComputerEducationWorld.com All Rights Reserved © RSS | CBSE | Education Boards Of India | What is My IP?