Ishar
21-10-2003, 13:30
Ciao a tutti io oggi ho realzzato questo metodo per una applicazione che stiamo realizzando(semplicemente è un controllo in un campo text per inserire solo numeri).La mia domanda è perchè mi vede lo zero non come un numero?
<html>
<head>
<title>Controllo Numeri</title>
<script language="javascript">
function trim(stringa) {
ris="";
indice=0;
for(var indice=0;indice<stringa.length;indice++) {
if(stringa.charAt(indice)!=" ") {
ris+=stringa.charAt(indice);
}
}
return ris;
}
function controlloNumeri() {
val="";
temp=document.all.testo.value;
for(var i=0;i<temp.length;i++){
if(!parseInt(temp.substring(i,i+1))) {
val+=" ";
alert("Non è un numero");
}else if(parseInt(temp.substring(i,i+1))){
val+=""+parseInt(temp.substring(i,i+1))+"";
}
}
test=trim(val);
document.all.testo.value=test
}
</script>
</head>
<body>
<form name="">
<input type="text" onkeypress="controlloNumeri();" name="testo" value="" size="20">
<br>
<br>
<input type="button" name="invio" value="Invio">
</form>
</body>
</html>
Azz la indentazione!!
<html>
<head>
<title>Controllo Numeri</title>
<script language="javascript">
function trim(stringa) {
ris="";
indice=0;
for(var indice=0;indice<stringa.length;indice++) {
if(stringa.charAt(indice)!=" ") {
ris+=stringa.charAt(indice);
}
}
return ris;
}
function controlloNumeri() {
val="";
temp=document.all.testo.value;
for(var i=0;i<temp.length;i++){
if(!parseInt(temp.substring(i,i+1))) {
val+=" ";
alert("Non è un numero");
}else if(parseInt(temp.substring(i,i+1))){
val+=""+parseInt(temp.substring(i,i+1))+"";
}
}
test=trim(val);
document.all.testo.value=test
}
</script>
</head>
<body>
<form name="">
<input type="text" onkeypress="controlloNumeri();" name="testo" value="" size="20">
<br>
<br>
<input type="button" name="invio" value="Invio">
</form>
</body>
</html>
Azz la indentazione!!