Javascript Change String to Integer |
|||||
197 views
we simply use parseInt() function to convert string into integer:Example1: parseInt(”34px”);
Example2:
|
Size:
-
<script type="text/javascript">function incre()
-
{
-
var increase = 10;
-
wid = parseInt(document.getElementById(’style_class’).style.width);
-
document.getElementById(’style_class’).style.width = wid + increase;
-
}</script>
-
<table border="0">
-
<tbody>
-
<tr>
-
<td id="style_class" style="width: 80px; height: 50px; background-color: red;"></td>
-
</tr>
-
</tbody></table>
-
<strong>Size:</strong>
-
-
<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 | |