Jump to content


Photo

Need help coding


  • Please log in to reply
7 replies to this topic

#1 oracle259

oracle259
  • Members
  • PipPipPip
  • Advanced Member
  • 119 posts

Posted 27 October 2006 - 08:05 PM

How do I allow users to add as many additional input boxes as they need. eg i have a conference room booking solution which provides for 6 participants how do i allow users to add another input box for more than 6 participants or delete extra input boxes for less than 6 participants but 1 input box must remain. Any ideas?

#2 Caesar

Caesar
  • Members
  • PipPipPip
  • Advanced Member
  • 1,025 posts

Posted 27 October 2006 - 08:08 PM

That's pretty vague. Can you maybe show some of your existing code and explain what you want your code to do? Is this on a page where users/the user needs to be logged in to edit the form?
PHP Ninja

#3 oracle259

oracle259
  • Members
  • PipPipPip
  • Advanced Member
  • 119 posts

Posted 27 October 2006 - 08:11 PM

i havent started coding this section bcause i knew it was going to give me troble so i decided to seek help first. But simply all i want to do i allow user s to click on a link that says 'add more members' when they click the link an additional input box appears and allows them to input the name of the individual. You can forget the delete part that seems overly complex

#4 sasa

sasa
  • Staff Alumni
  • Advanced Member
  • 2,804 posts
  • LocationHrvatska

Posted 27 October 2006 - 10:29 PM

try
<html>
<head>
<script language="JavaScript1.3" >
<!--
function row(){
	var table=window.document.getElementById("table1");
	var newRow = document.createElement("tr");
	var newCell=newRow.appendChild(document.createElement("td"));
	var input=newCell.appendChild(document.createElement("input"));
	input.type="text";
	input.name="frend[]";
	table.appendChild(newRow);
}
-->
</script>
</head>
<body>
<?php
if ($_POST) {
	//for ($x=0;$x<5;$x++) $c["cell".$x]=$_POST['cell'.$x];
	print "<pre>";
	print_r($_POST);
	print "</pre>";
}
?>
<form method="POST" action="">
<input type="button" value="AdRow" onclick="row()">
<input type="submit"><br />
<table id="table1" border="3px" width="20%" align="left" >
	<tr>
		<td width="20%" align="center">FREND</td>
	</tr>
</table><br />
</form>
</body>
</html>


#5 oracle259

oracle259
  • Members
  • PipPipPip
  • Advanced Member
  • 119 posts

Posted 30 October 2006 - 05:11 PM

Thanks it works. But im curious how do i amend the code to delete unwanted input boxes. For example i add the same person at boxes 3 and 8 of 21 how do i amend the code to allow users to delete each individual input box. May be i could add a link beside each input box that when click deletes that specific input box.

If you have any ideas pls tell me.

Thanks again

#6 oracle259

oracle259
  • Members
  • PipPipPip
  • Advanced Member
  • 119 posts

Posted 30 October 2006 - 05:34 PM

also how can i modify the jscript to allow for multiple input boxes in the same row. For example say that row 1 as 3 input boxes, same a row 2 but i want a 3rd row which must also have 3 input boxes how do i go about accomplishing that.

Thanks again 4 ur  help

#7 sasa

sasa
  • Staff Alumni
  • Advanced Member
  • 2,804 posts
  • LocationHrvatska

Posted 30 October 2006 - 09:25 PM

<html>
<head>
<script language="JavaScript1.3" >
<!--
var count = 0;
function row(){
	count = count +1;
	var table=window.document.getElementById("table1");
	var newRow = document.createElement("tr");
	newRow.id = 'row'+count;
	
	var newCell=newRow.appendChild(document.createElement("td"));
	for (var i=0;i<5;i++){
	var input=newCell.appendChild(document.createElement("input"));
	input.type="text";
	input.name="frend["+count+"][]";}
	var a = newCell.appendChild(document.createElement("a"));
	a.href="javascript:moveRow("+count+")";
	a.innerHTML ='Remove row';
	
	table.appendChild(newRow);
}
function moveRow(i) {
	var row = document.getElementById("row"+i);
	row.parentNode.removeChild(row);
}
-->
</script>
</head>
<body>

<?php
if ($_POST) {
	//for ($x=0;$x<5;$x++) $c["cell".$x]=$_POST['cell'.$x];
	print "<pre>";
	print_r($_POST);
	print "</pre>";
}
?>

<form method="POST" action="">
<input type="button" value="AdRow" onclick="row()">
<input type="submit"><br />
<table id="table1" border="3px" width="80%" align="left" >
	<tr>
		<td width="20%" align="center">FREND</td>
	</tr>
</table><br />
</form>
</body>


#8 oracle259

oracle259
  • Members
  • PipPipPip
  • Advanced Member
  • 119 posts

Posted 30 October 2006 - 10:05 PM

Thanks so much the script works perfectly. Im so happy right now you wouldnt believe.  :D




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users