hello all and thanks for reading this post.
i have a form with a text input, where the user can write the kind of teams where sorted on the game they played. but, i want to limit the "text" that the user is wrinting, cos the game is limited to 8 players, and i don't want them typeing something like 5vs6 or 7vs4 (game's max players numbers, how i said, is 8).
so, i though to take the string of the text input and scan the following things:
- it must be less than 4 characters in the string
- if there is no teams, the user must specify the number of players, just the number
- and finally, limit the number of players to 8
theres the code that i have:
function comprueba() {
if(document.pSubir.pJugado
resOtro.va
lue.length
> 4) {
alert("Error en el numero o equipos de jugadores\n\naoc-hispano.c
om");
document.pSubir.siguiente1
.value = "no";
}
if ((document.pSubir.pJugador
esOtro.val
ue.length >= 1) && (document.pSubir.pJugadore
sOtro.valu
e.indexOf(
"vs") == -1)) {
alert("Los equipos deben estar especificados siguiendo este formant:\n\n\t\t\tXvsY\n\n
Lo que significa que si es una partida de 3 contra 2, se deberÃa indicar:\n\n\t\t\t3vs2\n\n
aoc-hispan
o.com");
document.pSubir.siguiente1
.value = "no";
}
var uno=document.pSubir.pJugad
oresOtro.s
ubstring(0
,1);
var dos=document.pSubir.pJugad
oresOtro.s
ubstring(0
,4);
if((document.pSubir.pJugad
oresOtro.v
alue.index
Of("vs") == 1) && (uno+dos > 8)) {
alert("Contiene la cadena vs, y hay error en la cantidad de jugadores!");
document.pSubir.siguiente1
.value = "no";
}
}
well, the two first "if" works correctly, but the third part of the function, its where i have problems to get it working.
surely that you will see some crazyness in this code, cos i just began to work in javascript last saturday..
the idea is to take the values of X and Y, from XvsY (4vs3, 2vs3, 1vs5...) and save them on a variable, called "uno" for X, and "dos" for Y. and test if uno+dos (X+Y) its bigger than 8.
if its bigger a window.alert will appear warning to the user that theres an error and the siguiente1.value will be assigned to "no".
i know the third part of the function its some kinda badly done, so do not think that u must be based on it
thanks all