-5

I have 10 small text field boxes in HTML where I want users to enter numbers 1 to 10 - and the same number can not be entered twice in another box. I'm struggling to work out how to accomplish this in Javascript/jQuery.

Any help would be appreciated.

Helen Neely
  • 4,666
  • 8
  • 40
  • 64
  • 12
    What have you tried so far? Any code, a fiddle perhaps? When do you want to perform this operation? – Mike Sav Jun 08 '12 at 15:10
  • 6
    Doesn't sound particularly hard. What have you tried? – Jivings Jun 08 '12 at 15:10
  • 3
    @Helen, nearly 3 years on the site, you have asked some good questions (including a popular one voted `+19`), and now you're asking this. What happened? Is someone else tinkering with your account? – Frédéric Hamidi Jun 08 '12 at 15:15
  • @FrédéricHamidi I guess she didn't drink her first coffee yet. – Luc M Jun 08 '12 at 15:23

1 Answers1

1

Simply create an array with the values and check for duplication.

var formdata=new Array(); 
formdata[0]=document.getElementByid('id').value;
formdata[1]=document.getElementByid('id').value;
formdata[2]=document.getElementByid('id').value;

Now check for duplications in the array using the following - I guess the following question would be useful on stack overflow: Easiest way to find duplicate values in a JavaScript array. If the breakpoint is one simply display an alert() to the user to renter the data.

Instead of using documents.getElementById() you can also use

oForm = document.forms[index];
oText = oForm.elements["text_element_name"].value; OR 
oText = oForm.elements[index].value;

More information can be found at: http://www.javascript-coder.com/javascript-form/javascript-get-form.phtml

Community
  • 1
  • 1
user1092042
  • 1,297
  • 5
  • 24
  • 44