Solved

javascript to check running numbers enter in text field

Posted on 2006-11-29
3
271 Views
Last Modified: 2006-12-29
Hi guys, I have 8 textfields, which I need people to input numbers only 1-8, and each text field value cannot be duplicated.

I need a javascript to check that when I submit the form, any solutions? thanks


0
Comment
Question by:huang_ck
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 7

Accepted Solution

by:
vbandaru earned 500 total points
ID: 18038951
Here you go.. this script is length but it very generic

<html>
<body>
<form>
<input type="text" name="txt1" value=""></br>
<input type="text" name="txt2" value=""></br>
<input type="text" name="txt3" value=""></br>
<input type="text" name="txt4" value=""></br>
<input type="text" name="txt5" value=""></br>
<input type="text" name="txt6" value=""></br>
<input type="text" name="txt7" value=""></br>
<input type="text" name="txt8" value=""></br>
<input type="button" name="btn" value="Validate" onClick="validate()"></br>
</form>
<script language="javascript">
function validate(){
 var arryInput=document.getElementsByTagName("input");
 var arryLength=arryInput.length;
 var aryAllowedVals=new Array("1","2","3","4","5","6","7","8");
 var blnAllowedVal =false;
 var errMsg="";

 for(var i=0;i<arryLength;i++){
   if(arryInput[i].type=="text"){
      for(var k=0;k<aryAllowedVals.length;k++){
            blnAllowedVal=false
             if(arryInput[i].value==aryAllowedVals[k]){
                aryAllowedVals.splice(k,1);
                blnAllowedVal=true;
                break;
              }
      }
      if(!blnAllowedVal){
        errMsg +="A Bad value or duplicate value was entered in :" + arryInput[i].name + "\n";        
      }
   }
  }

if(errMsg!=""){
      errMsg +="The following values were not entered:" + aryAllowedVals.toString()
      alert(errMsg);
      return false;
}
if(aryAllowedVals.length!=0){
  alert("The following values were not entered:" + aryAllowedVals.toString());
  return false;
}
  return true;
}
</script>

</body>
</html>
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question