Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Test on multiple fields and update textbox based on result

Status
Not open for further replies.

kiwieur

Technical User
Apr 25, 2006
200
GB
Hi Team,

I am using this code to try and check if any of 8 textbox values = 2 and if so update a textbox with the letter Y and if not update with the letter N

Code:
<script language="JavaScript">
<!--
function CheckFail()
{

      if ( document.Entry.Check1.value == 2||document.Entry.Check2.value == 2||document.Entry.Check3.value == 2||document.Entry.Check4.value == 2||document.Entry.Check5.value == 2||document.Entry.Check6.value == 2||document.Entry.Check7.value == 2||document.Entry.Check8.value == 2)
      {
              document.forms['Entry'].elements['txtFailure'].value = "Y";
      }

      else 
      {
             document.forms['Entry'].elements['txtFailure'].value = "N";
}

//-->

</script>

However it doies not seem to be working could someone please have a look and let me know what I am doing wrong please


Regards

Paul

 
just a guess
use document.Entry.Check1.value == "2" instead of
document.Entry.Check1.value == 2
 
It's OK I have found another way to do this with the following code

Code:
<script type="text/javascript">
function checkBoxes(){
  boxArr = new Array("selCheck1", "selCheck2", "selCheck3", "selCheck4", "selCheck5", "selCheck6", "selCheck7", "selCheck8")
  dataFound = "No"
  for (x=0; x<boxArr.length; x++){
    boxVal = eval ("document.frmEnterRecord." + boxArr[x] + ".value")
    if (boxVal == "2"){
      dataFound = "Yes"
    }
  }
  document.frmEnterRecord.txtFailure.value = dataFound
}
</script>

and used this to trigger the event

Code:
<select name="selCheck8" id="selCheck8" onchange="checkBoxes()">

Regards

Paul

 
Word of the wise... don't use eval(). You should avoid ever using that. Using your code example above, you can do:

Code:
boxVal = document.frmEnterRecord[boxArr[x]].value;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top