Jump to content

Add rows to form.


ram4nd

Recommended Posts

I have a form in table and i need to add rows with javascript.

<script type="text/javascript">
Function addRowToTable()
{

}
</script>

<form action="something.php" method="post"><table border="0">
<tr>
<td><input type="text" name="text1_1" /></td>
<td><input type="text" name="text2_1" /></td>
<td><input type="text" name="text3_1" /></td>
<td><input type="text" name="text4_1" /></td>
</tr>
</table>

<input type="button" value="Add" onclick="addRowToTable();" />
<input type="hidden" name="rows" value="1" />

<input type="submit" name="saada" />
</form>

Link to comment
Share on other sites

Why am I not seeing javascript made fields?

<?php
static $body;
if(isset($_POST['saada']))

if(isset($_POST['text1_0'])) echo $_POST['text1_0'];
if(isset($_POST['text1_1'])) echo $_POST['text1_1'];
if(isset($_POST['text1_2'])) echo $_POST['text1_2'];

if(!isset($_POST['saada']))
$body = '<script type="text/javascript">
<!--
function lisa_rida()
{
var tabel = document.getElementById(\'tabel\');
var last_row = tabel.rows.length;
var iteration = last_row;
var row = tabel.insertRow(last_row);

form_1.rows.value = 1 + iteration;

//Cell 1
var text_box_1 = document.createElement(\'input\');
text_box_1.type = \'text\';
var cell_1 = row.insertCell(0);
text_box_1.name = \'text1_\' + iteration;
cell_1.appendChild(text_box_1);
//Cell 2
var text_box_2 = document.createElement(\'input\');
text_box_2.type = \'text\';
var cell_2 = row.insertCell(1);
text_box_2.name = \'text2_\' + iteration;
cell_2.appendChild(text_box_2);
//Cell 3
var text_box_3 = document.createElement(\'input\');
text_box_3.type = \'text\';
var cell_3 = row.insertCell(2);
text_box_3.name = \'text3_\' + iteration;
cell_3.appendChild(text_box_3);
//Cell 4
var text_box_4 = document.createElement(\'input\');
text_box_4.type = \'text\';
var cell_4 = row.insertCell(3);
text_box_4.name = \'text4_\' + iteration;
cell_4.appendChild(text_box_4);
}
//-->
</script>
<table border="0" id="tabel"><form action="'.$_SERVER['PHP_SELF'].'" method="post" id="form_1">
<tr>
<td><input type="text" name="text1_0" /></td>
<td><input type="text" name="text2_0" /></td>
<td><input type="text" name="text3_0" /></td>
<td><input type="text" name="text4_0" /></td>
</tr>
</table>
<input type="hidden" id="rows" name="rows" value="1" />

<input type="button" value="Lisa rida" onclick="lisa_rida();" />
<input type="submit" value="Saada" name="saada" />
</form>';
echo $body;
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.