0

Hello all,

I am stuck here with a problem. I want to check if someone enters a negative score on a multiple form page. I want that the edit field is red color if the score is negative.
I call htis function with the onblur event
input name="pickscorehome" type="text" class="pickedits" id="pickscorehome" onblur="checknumberhome(this.form);" onchange="Setradio(this.form);"

The problem is that there are an undefined number of forms on the page that are generated out of a database. How can i do that for each form ? Seems works only on
the first form.

Thanks for any hints.
Peter

function checknumbervisitor(f)
{
    if(parseFloat(f.pickscorevisitor.value)<0)
    {
      alert("There are no negative scores. Please enter a positive number");
      document.getElementById('pickscorevisitor').style.backgroundColor="#FF0000";
    }
    else
    {
    document.getElementById.getElementById('pickscorevisitor').style.backgroundColor="#FFFFFF"; 
    }
}

Edited by Reverend Jim: Fixed formatting

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by Gerbiler
0

have each input tag that you want to turn red when a negative number is entered have an onblur event that triggers a general function checkelement and have them pass themselves. I don't think I am explaining this well.

<input id="input1" name="input1" onblur="checkelement(this)">
<input id="input2" name="input2" onblur="checkelement(this)">
<input id="input3" name="input3" onblur="checkelement(this)">
<script type="text/javascript">
function checkelement(element){
   if(parseFloat(element.value)<0)
   {
      alert("There are no negative scores. Please enter a positive number");
      element.style.backgroundColor="#FF0000";
   }
   else
   {
      element.style.backgroundColor="#FFFFFF";
   }
}
</script>

Edited by Gerbiler: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.