0

I'm building a simple sudoku level checker. I need to loop through each lines,columns,each 3x3 boxes. In this code i have a first 3 numbers of first line. How i can loop trough id's numbers so i could check for a count of numbers inside first line?

<div id="firstline">
   <td width="30" height="30">
      <div id="1">
         <input class="one_number" maxlength="1" type="text" onkeypress='validate(event)'>
      </div>
   </td>
   <td width="30" height="30">
      <div id="2">
         <input class="one_number" maxlength="1" type="text" onkeypress='validate(event)'>
      </div>
   </td>
   <td width="30" height="30">
      <div id="3">
         <input class="one_number" maxlength="1" type="text" onkeypress='validate(event)'>
      </div>
   </td>
</div>
Lord Grosse Jeanine
  • 1,111
  • 10
  • 29

2 Answers2

0

I would suggest using jQuery for this. It's a javascript framework with alot of built in functionality, including what you need. You can download it here.

The looping can be achieved using a selector for the children of firstline and then looping through them using the each function.

Glenn Vandamme
  • 1,146
  • 8
  • 23
-1

Loop through each, refer this.

  $('.one_number').each(function(){
    var theID = $(this).attr('id');   
    // Do whatever with each and stored the ID as var
  });
Apoorv Awasthi
  • 1,397
  • 1
  • 12
  • 20
ggdx
  • 3,024
  • 4
  • 32
  • 48