Hi I want to add tbody dynamically so each time type number in in plannedvisit is add one more tbody But I got an error. I am using jsf and javaScript here is what I've done so far:
I am calling the javascript function by entering numeber:
<h:inputText type="number" id="plannedVisit" styleClass="form-control"
onkeyup=" addInput('dynamicInput'); return false; " required="true" >
</h:inputText>
<div class="form-group"><div class= "col-sm-6" >
<div id="nextVisitTable" class="input-group table">
<table id="nextVisitTable1" class="table" style="width:10%;margin- top:-210px; margin-left:90px; overflow:auto;">
<thead>
<tr>
<th>Reason</th>
<th>Date</th>
<th>Time</th>
</tr>
</thead>
<tbody>
<tr>
<td><h:inputText type="number" class="reasonOfVisit" styleClass="form- control"
required="true">
</h:inputText></td>
<td><h:inputText type="date" class="reasonOfVisit" styleClass="form-control"required="true">
</h:inputText></td>
</tr>
</tbody>
</table>
</div>
</div>
and this is the Script:
function addInput(divName){
var counter = 1;
console.log(counter);
var limit = 3;
if(counter == limit){
alert("You have Reached the Limit");
}
else {
var newdiv = document.createElement('tbody');
newdiv.innerHTML = "<tr><td><h:inputText type="number" class="reasonOfVisit" styleClass="form-control" required="true">
</h:inputText></td>
<td><h:inputText type="date" class="reasonOfVisit" styleClass="form-control" required="true">
</h:inputText></td>
</tr>";
counter++;
}
}
and the error is: SyntaxError: missing ; before statement at this line
newdiv.innerHTML = "<tr><td><h:inputText type="number....</tr>"
I am not sure is it correct way or Not Please help if u have any idea. Thanks