echo dynamically added input fields for different sections

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
naph
Forum Newbie
Posts: 1
Joined: Tue Jul 12, 2016 9:39 am

echo dynamically added input fields for different sections

Post by naph »

I am using jquery to add input fields dynamically for two table data: Skills and Duties. Each is to have dynamically added fields below it. when i enter data and submit, only one table return the values. Both are echo ing results BUT cant show results at the same time.
What could be wrong with my code?
BELOW IS MY CODE:

(CODE FOR JQUERY)

Code: Select all

<script type="text/javascript">
var i = 1;
function addSkill(){
	if (i <= 10){
		i++; 
		var 
		div = document.createElement('div');
		div.innerHTML = '<input type="text" name="skill_'+i+'" ><input type="button" id="add_skill()"onClick="addSkill()" value="+" /><input type="button" value="-"onclick="removeSkill(this)">'; 
		document.getElementById('skills').appendChild(div);
		}
} 
function removeSkill(div) { document.getElementById('skills').removeChild( div.parentNode );
	i--; 
} 
</script>

<script type="text/javascript">
var i = 0;
function addDuty(){
	if (i <= 10){
		i++; 
		var 
		div = document.createElement('div');
		div.innerHTML = '<input type="text" name="child_'+i+'" ><input type="button" id="add_duty()" onClick="addDuty()" value="+" /><input type="button" value="-" onclick="removeaaaduty(this)">';
                document.getElementById('duties').appendChild(div);
        }
 } 
function removeDuty(div) {
  document.getElementById('duties').removeChild( div.parentNode ); 
  i--;
}
</script>
(PHP CODE)

Code: Select all

<?php 
if(isset($_POST['skill']))
{ $skill = $_POST['skill']; 
$skilllist = ""; 
$more = TRUE; 
$i = 1; 
while ($more){ 
if ((isset($_POST['skill_'.$i])) && ($_POST['skill_'.$i] != "")){
	$skilllist .= '<li>'.$_POST['skill_'.$i];
	$skilllist .= "<br />";
}	
	else {
		$more = FALSE;
		}
		$i++;
		}
    echo "<li>".$skill; echo "<br />";
	echo $skilllist;
	} ?>
<?php 

if(isset($_POST['duty']))
{ $duty = $_POST['duty']; 
$childlist = ""; 
$more = TRUE; 
$i = 1; 
while ($more){ 
if ((isset($_POST['child_'.$i])) && ($_POST['child_'.$i] != "++")){
	$childlist .= $_POST['child_'.$i]; 
	$childlist .= "<br />"; } 
	else {
		$more = FALSE;
		}
		$i++;
		} 
		echo $duty; echo "<br />";
		echo $childlist; } 
?>
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: echo dynamically added input fields for different secti

Post by Christopher »

Do you think the problem is in the code that PHP is generating? Or in the Javascript that is working on the generated code? Can you provide example output of the PHP so we can see what the Javascript is working with in the browser?
(#10850)
Post Reply