Page 1 of 1

echo dynamically added input fields for different sections

Posted: Tue Jul 12, 2016 9:57 am
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; } 
?>

Re: echo dynamically added input fields for different secti

Posted: Wed Jul 13, 2016 6:14 pm
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?