hi, i need validate dinamic table javascript before i insert data do db, i m new here. please help me.
here is code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
</script>

<script type="text/javascript"> 
/*<![CDATA[*/ 

function addRow() 
{ 
var tbl = document.getElementById('mySampleTable'); 
var lastRow = tbl.rows.length; 

var iteration = lastRow; 
var row = tbl.insertRow(lastRow); 

var cellLeft = row.insertCell(0); 
var doc = document.createElement('input');
doc.type = 'text'; 
doc.name = 'doc[]';  
doc.id = 'doc' + iteration; 
doc.style.width="100%"; 
cellLeft.appendChild(doc); 

var id_age = "AGE"+iteration;


var func = row.insertCell(1);  
var nome = document.createElement('input'); 

nome.type = 'text'; 
nome.name = 'nome[]';
nome.id = 'nome' + iteration; 

nome.style.width="100%"; 


func.appendChild(nome);
} 

function removeRow() 
{ 
// grab the element again! 
var tbl = document.getElementById('mySampleTable'); 
// grab the length! 
var lastRow = tbl.rows.length; 
// delete the last row if there is more than one row! 
if (lastRow > 1) tbl.deleteRow(lastRow - 1); 
} 
/*]]>*/ 
</script> 

<body>
<form id="form1" name="form1" method="post" onSubmit="return valida(this)"  enctype="multipart/form-data" action="send.php">
<table width="50%" height="36" border="3" cellpadding="2" cellspacing="2" id="mySampleTable">
            <tr>
              <th width="9%" class="style5" scope="col"><div align="left">Doc Ident</div></th>
              <th width="26%" scope="col"><div align="left" class="style5">Name</div></th>
            </tr>



          </table>
            <p align="lefth">
        <input type="button" value="Add" onClick="addRow();" /> 
        <input type="button" value="Remove" onClick="removeRow();" /> 
        <input name="send" type="submit" value="Send"/>
        </p>
        <p>&nbsp;</p></th>

         <td></td>
        </form>
</body>

</html>

Use the rows[] and cells[] collections to validate the desired cell(s) in the desired row(s).

Using them together rows[i].cells[j] makes accessing a table almost as easy as accessing a two-dimensional array.

Sorry, but i try and no results, i really need your help!!!

i try and no results

What did you try?

listen i try do like you say but...no results, so can you do that for me?? i m new in javascript. please help - me.

i try do like you say

Show your code.

What you previously posted was so badly formed that I'm surprised it even displayed.

Perhaps you will make more progress if you start with this version of your code

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta name="generator" content=
    "HTML Tidy for Windows (vers 25 March 2009), see www.w3.org" />
    <meta http-equiv="Content-Type" content=
    "text/html; charset=us-ascii" />
    <title>
      Untitled Document
    </title>
    <script type="text/javascript">

function addRow() {
    var tbl = document.getElementById('mySampleTable');
    var lastRow = tbl.rows.length;
    var iteration = lastRow;
    var row = tbl.insertRow(lastRow);
    var cellLeft = row.insertCell(0);
    var doc = document.createElement('input');
    doc.type = 'text';
    doc.name = 'doc[]';
    doc.id = 'doc' + iteration;
    doc.style.width = "100%";
    cellLeft.appendChild(doc);
    var id_age = "AGE" + iteration;
    var func = row.insertCell(1);
    var nome = document.createElement('input');
    nome.type = 'text';
    nome.name = 'nome[]';
    nome.id = 'nome' + iteration;
    nome.style.width = "100%";
    func.appendChild(nome);
}
function removeRow() {
    // grab the element again! 
    var tbl = document.getElementById('mySampleTable');
    // grab the length! 
    var lastRow = tbl.rows.length;
    // delete the last row if there is more than one row! 
    if (lastRow > 1) tbl.deleteRow(lastRow - 1);
}
    </script>
  </head>
  <body>
    <form id="form1" name="form1" method="post" onsubmit=
    "return valida(this)" enctype="multipart/form-data" action=
    "send.php">
      <p align="lefth">
        <input type="button" value="Add" onclick="addRow();" />
        <input type="button" value="Remove" onclick=
        "removeRow();" /> <input name="send" type="submit" value=
        "Send" />
      </p>
      <p>
        &nbsp;
      </p>
    </form>
    <table width="50%" height="36" border="3" cellpadding="2"
    cellspacing="2" id="mySampleTable">
      <tr>
        <th width="9%" class="style5" scope="col">
          <div align="left">
            Doc Ident
          </div>
        </th>
        <th width="26%" scope="col">
          <div align="left" class="style5">
            Name
          </div>
        </th>
      </tr>
    </table>
  </body>
</html>

(in which the serious errors have been corrected).

Obviously, since there is no function valida() in what you posted thus far, whatever it is supposed to be doing won't be done.

i do not know if you understand, i want to validate the form with javascript, with alert message if the box was empty, before i send to database,
that's what i want know.

thanks

i do not know if you understand, i want to validate the form with javascript, with alert message if the box was empty, before i send to database,

I understand that completely.

What I want you to understand is that function valida() [which your existing code would call - if you had written any part of it] is the place where you would put that alert [and the test(s) leading up to it]. I won't write it for you, but if you come up with code that needs to be fixed, I will help.

please someone can do that for me?????? do that function valida() for me...please.

please someone help!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.