New with Javascript: Who like to help me with a loop function?

J

jack vermeulen

Hello,

I'm working on a script(for giving points to a soccergame 0, 1 or 3 points)
that give a value to a hidden field, i got a function but only works on 1
field.

I want that the function loops till all hidden fields are fill in.

Here's what i got so far:

function myfunction()
{

if (document.form1.hgoals.value == document.form1.agoals.value){
document.form1.hpoints.value = (1)
document.form1.apoints.value = (1)
}
else if(document.form1.hgoals.value > document.form1.agoals.value){
document.form1.hpoints.value = (3)
document.form1.apoints.value = (0)
}
else if(document.form1.hgoals.value < document.form1.agoals.value){
document.form1.hpoints.value = (0)
document.form1.apoints.value = (3)
}



I hope someone can help me.

Jack
 
S

Sergey I.Grachyov

Hi!

1.
Not sure what problem you have,
but I may use this

if (document.form1.hgoals.value - document.form1.agoals.value > 0)

i.e. - compare number with "0"
This code:

if(document.form1.hgoals.value > document.form1.agoals.value)

may compare values as STRINGs, not as NUMBER

2.
Also - you may use this syntax: document.forms['form1'].hgoals.value
It's always working better.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top