I have a form in yii and there is a text field named certificate_name in it. Now i want that when I click on the plus icon, the text field should increment by one and appear below the previous field.
Here is my php code:
<?php for ($i = 0; $i <= $_REQUEST['total_certi']; $i++) { ?>
<div class="pr-ser">
<div class="row">
<?php echo $form->labelEx($model4, 'certificate_name'); ?>
<?php echo $form->textField($model4, 'certificate_name', array('maxlength' => 300)); ?>
<?php echo $form->error($model4, 'certificate_name'); ?>
</div><!-- row -->
</div>
<?php } ?>
<p id="demo"></p>
<div class="row buttonsub">
<input type="button" id ="trainer_certi" onclick="myFunction()" value="Add" />
</div>
There is no issue if I increment the whole div instead of a fild. I can manage this. My JavaScript code is as below:
<script>
function myFunction() {
var value = parseInt(document.getElementById('demo').value, 10);
value = isNaN(value) ? 0 : value;
value++;
document.getElementById('demo').value = value;
var total_certi = value;
alert(total_certi);
}
</script>
If I get the result in $_REQUEST['total_certi']
and if it works in for loop then I complete my work.
Here I can get incremented value in alert in script but how to apply this value to php and increment the number of field without reloading page?