good idea, but i want to do like i said
Main Topics
Browse All Topicshello 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
alert("Error en el numero o equipos de jugadores\n\naoc-hispano.c
document.pSubir.siguiente1
}
if ((document.pSubir.pJugador
alert("Los equipos deben estar especificados siguiendo este formant:\n\n\t\t\tXvsY\n\n
document.pSubir.siguiente1
}
var uno=document.pSubir.pJugad
var dos=document.pSubir.pJugad
if((document.pSubir.pJugad
alert("Contiene la cadena vs, y hay error en la cantidad de jugadores!");
document.pSubir.siguiente1
}
}
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
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Try this:
var uno=parseInt(document.pSub
var dos=parseInt(document.pSub
if((document.pSubir.pJugad
alert("Contiene la cadena vs, y hay error en la cantidad de jugadores!");
document.pSubir.siguiente1
}
Here my idea:
<html>
<head>
<script>
function setCount(theSel){
unoOpt = theSel.form.uno.options;
dosOpt = theSel.form.dos.options;
selUno = theSel.form.uno;
selDos = theSel.form.dos;
optUno = selUno.options;
optDos = selDos.options;
valUno = selUno.value;
valDos = selDos.value;
equipCount = theSel.value;
oldCount = optUno.length;
if(equipCount>oldCount){
for(i=oldCount+2;i<=equipC
optUno[i-2] = new Option(i, i);
optDos[i-2] = new Option(i, i);
}
} else {
optUno.length = equipCount-1;
optDos.length = equipCount-1;
}
}
function setOther(theSel){
unoOpt = theSel.form.uno.options;
dosOpt = theSel.form.dos.options;
selUno = theSel.form.uno;
selDos = theSel.form.dos;
optUno = selUno.options;
optDos = selDos.options;
valUno = selUno.value;
valDos = selDos.value;
equipCount = theSel.form.numEquip.value
optUno.length = 0;
optDos.length = 0;
for(i=1;i<=equipCount;i++)
if(i==valUno){
optUno[optUno.length] = new Option(i, i, true, true);
} else if(i==valDos){
optDos[optDos.length] = new Option(i, i, true, true);
} else {
optUno[optUno.length] = new Option(i, i);
optDos[optDos.length] = new Option(i, i);
}
}
}
</script>
</head>
<body>
<form name="pSubir">
Numero o Equipos:
<select name="numEquip" onChange="setCount(this)">
<option value="2" selected>2
<option value="3">3
<option value="4">4
<option value="5">5
<option value="6">6
<option value="7">7
<option value="8">8
</select><br>
Play:
<select name="uno" onChange="setOther(this)">
<option value="1" selected>1
</select>
vs
<select name="dos" onChange="setOther(this)">
<option value="2" selected>2
</select>
</form>
</body>
</html>
Sorry, slightly reduced:
<html>
<head>
<script>
function setCount(theSel){
optUno = theSel.form.uno.options;
optDos = theSel.form.dos.options;
equipCount = theSel.value;
oldCount = optUno.length;
if(equipCount>oldCount){
for(i=oldCount+2;i<=equipC
optUno[i-2] = new Option(i, i);
optDos[i-2] = new Option(i, i);
}
} else {
optUno.length = equipCount-1;
optDos.length = equipCount-1;
}
}
function setOther(theSel){
selUno = theSel.form.uno;
selDos = theSel.form.dos;
optUno = selUno.options;
optDos = selDos.options;
valUno = selUno.value;
valDos = selDos.value;
equipCount = theSel.form.numEquip.value
optUno.length = 0;
optDos.length = 0;
for(i=1;i<=equipCount;i++)
if(i==valUno){
optUno[optUno.length] = new Option(i, i, true, true);
} else if(i==valDos){
optDos[optDos.length] = new Option(i, i, true, true);
} else {
optUno[optUno.length] = new Option(i, i);
optDos[optDos.length] = new Option(i, i);
}
}
}
</script>
</head>
<body>
<form name="pSubir">
Numero o Equipos:
<select name="numEquip" onChange="setCount(this)">
<option value="2" selected>2
<option value="3">3
<option value="4">4
<option value="5">5
<option value="6">6
<option value="7">7
<option value="8">8
</select><br>
Play:
<select name="uno" onChange="setOther(this)">
<option value="1" selected>1
</select>
vs
<select name="dos" onChange="setOther(this)">
<option value="2" selected>2
</select>
</form>
</body>
</html>
hi again
thanks brgivens and grettings Zvonko
zvonko, your idea is not what i am looking for, its different, but a good idea...
i have tested this one and looks fine. but it does not do what im asking for (im agree with your idea), so how about two selects how brgivens said, but, when selecting for example 2 on the first select, it will change the options automatically in the second select, doing that the second select only can have 6 options.. for example:
case 1:
--------------------------
select1 [ 3 ] select2 [ 1 ]
[ 2 ]
[ 3 ]
[ 4 ]
[ 5 ]
select1 value is 3, now, select2 can only have 5 values (3+5=8)
--------------------------
case 2:
--------------------------
select1 [ 5 ] select2 [ 1 ]
[ 2 ]
[ 3 ]
select1 value is 5, now, select2 can only have 3 values (5+3=8)
--------------------------
this idea will work perfectly on my form :)
Like this:
<html>
<head>
<script>
function setCount(theSel){
equipCount = theSel.value;
optDos = theSel.form.dos.options;
optDos.length=0;
for(i=1;i<=8-equipCount;i+
optDos[i-1] = new Option(i, i);
}
}
</script>
</head>
<body>
<form name="pSubir">
<select name="numEquip" onChange="setCount(this)">
<option value="1">1
<option value="2">2
<option value="3">3
<option value="4">4
<option value="5">5
<option value="6">6
<option value="7" selected>7
</select>  
<select name="dos">
<option value="1" selected>1
</select>
</form>
</body>
</html>
Business Accounts
Answer for Membership
by: brgivensPosted on 2004-04-14 at 00:54:36ID: 10821192
Instead of using a single textbox, how about this?
<select>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
</select> vs <select>
<option></option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
</option>