Jump to content
Sign in to follow this  
costricardo

percorrer form

Recommended Posts

costricardo

Boas pessoal  :P

Estava aqui a fazer um code que quando clicasse em um numero da form ele ficasse verde e imprimisse po input text. Na realidade ele faz isso, mas também estava a tentar fazer uma função que quando clicasse no botao validar ele colocasse tudo como tava, ou seja da mesma cor.

Mas não estou a conseguir.

my code:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>  <head>
    <title></title>


    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" type="text/css" href="totoloto.css">

    <script type="text/javascript">



            function recebe(formID, suck,id)
            {
                String = document.getElementById(formID).k.value; //vai buscar o que ja la esta
                String2 = suck;
                String3 = String + String2;

        document.getElementById(formID).k.value =String3;

         document.getElementById(id).style.background = "green";

        


            }

            function take(formID)
            {

                for(k=0; k<9;k++)
                    {
                       formID[k].style.background ="white";
                    }
            }
          
        </script>


  </head>
  <body>

      <form id="toto">


      <table>
          
          <tr>

              <td id="1" onclick="recebe('toto','1',id)">1</td>
              <td id="2" onclick="recebe('toto',id,id)">2</td>
              <td id="3" onclick="recebe('toto',id,id)">3</td>
              <td id="4" onclick="recebe('toto',id,id)">4</td>
              <td id="5" onclick="recebe('toto',id,id)">5</td>
              <td id="6" onclick="recebe('toto',id,id)">6</td>


            
          </tr>

          <tr>

              <td>7</td> <td>8</td> <td>9</td> <td>10</td> <td>11</td> <td>12</td>

          </tr>

          <tr>

              <td>13</td> <td>14</td> <td>15</td> <td>16</td> <td>17</td> <td>18</td>

          </tr>

          <tr>

              <td>19</td> <td>20</td> <td>21</td> <td>22</td> <td>23</td> <td>24</td>

          </tr>
          <tr>

              <td>1</td> <td>2</td> <td>3</td> <td>4</td> <td>5</td> <td>6</td>

          </tr>
          <tr>

              <td>1</td> <td>2</td> <td>3</td> <td>4</td> <td>5</td> <td>6</td>

          </tr>
          <tr>

              <td>1</td> <td>2</td> <td>3</td> <td>4</td> <td>5</td> <td>6</td>

          </tr>
          <tr>

              <td>1</td> <td>2</td> <td>3</td> <td>4</td> <td>5</td> <td>6</td>

          </tr>
          <tr>

              <td>1</td> <td>2</td> 

          </tr>
          
      </table>

          Numeros: <input type="text" id="k">
          <br>
          <input type="button" value="Validar" onclick="take('toto')" >


      </form>





  </body>
</html>


I´m a Geek and you?www.tecnologias.in

Share this post


Link to post
Share on other sites
cra2sh

Experimenta assim

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>TOTO</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">
function recebe(formID, suck, id)
{
String = document.getElementById(formID).k.value; //vai buscar o que ja la esta
    String2 = new Number(suck);
    String3 = String + String2;

document.getElementById(formID).k.value = String3;

document.getElementById(id).style.background = "green";
};

function take()
{
for (var k = 1; k <= 6; k++)
{
	document.getElementById(k).style.background = "white";
};
};
</script>
</head>
<body>
<form id="toto">
<table>
<tr>
<td id="1" onclick="recebe('toto', 1, id)">1</td>
<td id="2" onclick="recebe('toto', 2, id)">2</td>
<td id="3" onclick="recebe('toto', 3, id)">3</td>
<td id="4" onclick="recebe('toto', 4, id)">4</td>
<td id="5" onclick="recebe('toto', 5, id)">5</td>
<td id="6" onclick="recebe('toto', 6, id)">6</td>
</tr>
</table>
Numeros: <input type="text" id="k">
<br />
<input type="button" value="Validar" onclick="take()" >
</form>
</body>
</html>

Nunca te esqueças que o ID é unico, e estas a utilizar o mesmo ID para todos, quando for assim utiliza classes

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.