|
Posted by petersprc on 08/12/07 07:18
Yeah, as Gerard Vignes mentioned, this can be done with DHTML as well
as the other methods he mentioned. Here's one example:
form.php:
<?
<script type="text/javascript">
function addItems(count)
{
for (var i = 0; i < count; i++) {
var tbl = document.getElementById("items")
var row = tbl.insertRow(tbl.rows.length)
var cell1 = row.insertCell(0)
cell1.innerHTML = '' + tbl.rows.length + '. '
var cell2 = row.insertCell(1)
cell2.innerHTML = '<input name="items[]">'
var cell3 = row.insertCell(2)
var html = '<a href="#" onClick=\'removeItem(this);\'>'
html = html + 'Remove</a>'
cell3.innerHTML = html
}
}
function removeItem(link)
{
var row = link.parentNode.parentNode;
var tbl = document.getElementById("items")
tbl.deleteRow(row.rowIndex)
for (var i = 0; i < tbl.rows.length; i++) {
tbl.rows[i].cells[0].innerHTML = '' + (i + 1) + '. '
}
}
function onLoad()
{
addItems(3)
return true
}
</script>
<body onLoad="return onLoad();">
<? if ($_SERVER['REQUEST_METHOD'] == 'POST') { ?>
<h4>You Entered</h4>
<ul>
<?
foreach ($_POST['items'] as $item) {
$item = trim($item);
if ($item != '') {
?>
<li><?= htmlentities($item) ?></li>
<? } ?>
<? } ?>
</ul>
<? } ?>
<form action="form.php" method=post>
<h4>Items</h4>
<table id=items cellpadding=3 cellspacing=0 border=0>
</table>
<p><a href="#" onClick="addItems(1);">Add Item</a></p>
<p><input type=submit value=" OK "></p>
</form>
?>
You could also use the ActiveWidgets Grid control, which allows
inserting and removing rows dynamically:
http://www.activewidgets.com/grid/
On Aug 10, 8:03 am, Daniel <d_pinea...@hotmail.com> wrote:
> Hello,
>
> Could someone explain/demonstrate how I can create a 'continuous
> form' (similar to access) but in a webpage using php. What I am
> trying to do is have and entry input, if the user enters info then
> make another input available and so on. This way they can enter as
> many items as they need. Then loop through each of their entry and
> perform my action. If there is a proper web term for what I am trying
> to accomplish could you please let me know so I start using the proper
> terminology.
>
> Thank you for the help.
>
> Daniel
Navigation:
[Reply to this message]
|