Click to See Complete Forum and Search --> : Number Calculation
mexavin
11-07-2003, 10:51 AM
This should be easy, but I can't find an example ANYWHERE on the web! I just need to know how many numbers are chosen in a text box.
EXAMPLE: user enters the following:
101-105, 107, 109, 110-115
How do I calculate that this should equal: 13
Thanks,
Mex
Charles
11-07-2003, 11:22 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>Example</title>
<style type="text/css">
<!--
label {display:block; margin:1em 0em}
input {display:block}
-->
</style>
<script type="text/javascript">
<!--
Array.prototype.max = function () {
if (this.length == 0) return undefined;
var n = Number(this[0]);
for (var i=1; i<this.length; i++) {n = Math.max(n, this[i])};
return n;
}
Array.prototype.min = function () {
if (this.length == 0) return undefined;
var n = Number(this[0]);
for (var i=1; i<this.length; i++) {n = Math.min(n, this[i])};
return n;
}
// -->
</script>
<form action="">
<div>
<label>Range<input onchange="alert (this.value.split(/[\s,-]+/).max() - this.value.split(/[\s,-]+/).min() - 1)" type="text"></label>
</div>
</form>
olerag
11-07-2003, 11:50 AM
If there is a planet called JavaScript then Charles must
be its ruler.