|
|
parseInt function for string to numberBy using parseInt function we can convert strings to numbers. This is similar to parseFloat function but it changes the string to Integer. Using this function we can only convert string numbers to numeric data but alphabetic characters we can't convert.
This function can only convert strings which are in the form of numbers and it can't change any alphabet or strings.
Here is a demo where inputs are used after passing through parseInt function. The output is then considered for calculation.
Enter some numbers with decimal values here.
Here is the code of this demo
<html>
<head>
<title>(Type a title for your page here)</title>
<script type="text/javascript">
function to_add(){
document.f1.t3.value=parseInt(document.f1.t1.value) + parseInt(document.f1.t2.value);
}
</script>
</head>
<body>
<form method=post name=f1 ><br>
Enter fist value<input type=text name=t1 onBlur="to_add();"><br>
Enter Second value<input type=text name=t2 onBlur="to_add();"><br>
Sum <input type=text name=t3>
</form>
</body>
</html>
| |
|
|
|
|
|