I have tried in this strategy->
<script type="text/javascript">
$(document).ready(function(){
var countPos=0;
var add_button=$('#add_position');
var wrapper=$('#position_fields');
window.console && console.log('Document ready called');
//When the user clicks on the add button then It inserts these input fields
$(add_button).click(function(event){
// http://api.jquery.com/event.preventdefault/
event.preventDefault();
if ( countPos >=9 ) {
alert("Maximum of nine position entries exceeded");
return;
}
countPos++;
window.console && console.log("Adding position "+countPos);
$(wrapper).append(
'<div id="position'+countPos+'"> \
<p>Year: <input type="text" name="year'+countPos+'" value="" /> \
<input type="button" value="-" \
onclick="$(\'#position'+countPos+'\').remove();return false;"></p> \
<textarea name="desc'+countPos+'" rows="8" cols="80"></textarea>\
</div>');
});
});
Here is my html segment->
<div class="container">
<h1>Ashiful Islam Prince's Resume Registry</h1>
<h1>Editing Profile for UMSI</h1>
<?php
if(isset($_SESSION['profile_error'])) {
$error = $_SESSION['profile_error'];
unset($_SESSION["profile_error"]);
echo '<span class="text-danger">';
echo $error;
echo '</span>';
}
?>
<form method="post">
<p>First Name:
<input type="text" name="first_name" value="<?php
echo $firstName;
?>"
></p><br>
<p>Last Name:
<input type="text" name="last_name" value="<?php
echo $lastName;
?>"</p>
<p>Email:
<input type="text" name="email" value="<?php
echo $Email;
?>"</p><br>
<span class="text-danger">
<?php
if(isset($email_sign_error))
echo $email_sign_error;
?>
</span>
<p>Headline:<br/>
<input type="text" name="headline" value="<?php
echo $Headline;
?>"</p>
<p>Summary:<br/>
<textarea name="summary" rows="8" cols="80">
<?php
echo $Summary;
?>
</textarea>
<p>Position : <input type="submit" class="add_position" id="add_position"
name="addPosition" value="+">
<div class="position_fields" id="position_fields">
</div>
<p>
<input type="submit" value="Save" name="btn" class="btn btn-primary">
<input type="submit" name="cancel" value="Cancel">
</p>
</form>
</div>
</div>
</div>
The problem I have faced: In this above program I can display the input fields when the user clicks on the add button. But I want to display these fields when the page loads mean without clicking on the add button I want to print those fields. How can I go to my destination?
Here is my php code for fetching data from the database:
<?php
try{
//Need to make a connection
$con=new PDO("mysql:host=localhost;dbname=courseraassignment","root","");
$statement=$con->prepare("select * from position
where profile_id=:profile_id");
$statement->execute(array(
':profile_id'=>$_REQUEST['profile_id']
));
foreach($statement as $row){
echo $row['year'];
echo $row['description'];
echo "<br>";
}
}catch(PDOException $e){
echo "error".$e->getMessage();
}
?>
From this code I am fetching year and description from the position table and want to show these value to these input fields when the page loads.