I have the following code that should be put in control of the image interface but it does not work. Please some advice so that the amount that I send to a text box and show me how many thousands, hundreds, tens and units has.
How can I separate an amount in thousands, hundreds, tens and units and count how many of each unit?
function separarSifras(cantidad) {
if (cantidad == "") {
alert("Escribe una cantidad por favor");
} else {
if (!isNaN(cantidad.value)) {
alert("Escibe solo numeros");
} else {
var cadeSifra = new String(cantidad.value);
var longitudSifra = cantidad.length;
var millares = "";
var centenas = "";
var decenas = "";
var unidades = "";
for (cont = 0; cont < longitud.length; cont++) {
if (cadeSifra.charAt(cont) == '1') priNum++;
}
}
}
}
<h1 align="center">Clasificador de monedas</h1>
<form>
<table align="center" border=0>
<tr>
<th>
Ingresa una cantidad:
<input type="text" name="cantidad" maxlength="5" />
<input type="button" value="Acomodar" onClick="separarSifras(this.form.cantidad)" />
</th>
<td align=center>
<input type="button" value="Reiniciar" onclick="window.location.reload()" />
</td>
</tr>
</table>
</form>
<br>
<table align="center" border="1">
<tr>
<td>Millares</td>
<td>Centenas</td>
<td>Decenas</td>
<td>Unidades</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
I get the error
ReferenceError: length is not defined