Skip to content
Advertisement

Dynamically add textbox in jsp

I want to add jsp textbox dynamically. I am using the following code single textbox.

<div id="certificationtog">
	<p class="setting">
	<input type="button" id="addrows" name="addrows" class="addperson" value="Add Rows">
    <input type="button" id="removerows" class="removerows" value="Delete Rows" />  
	<br><br>
  <span style="width: 0px; margin-left: 20px; font-weight: bold; float: none;">Diploma/Certificate:</span>
	<form:input path="certification" type="text" title="Only Text Allowed" pattern="[a-zA-Zs'.,@:&?!()$#/\]+" />									 
								 
    </p>
</div>

Here, while clicking addrow button, I want to add the textbox dynamically.

Advertisement

Answer

try this:

<script type="text/javascript">
   function add() {
     var element = document.createElement("input");
     element.setAttribute("type", "text");
     element.setAttribute("name", "mytext");
    var spanvar = document.getElementById("myspan");
    spanvar .appendChild(element);
   }
</SCRIPT>
<div id="certificationtog">
   <p class="setting">
      <input type="button" id="addrows" name="addrows" class="addperson" 
        value="Add Rows" onclick="add();">
      <input type="button" id="removerows" class="removerows" 
        value="Delete Rows" />  
      <span id="myspan"></span>
      <br><br>
      <span style="width: 0px; margin-left: 20px; font-weight: bold; float: none;">
        Diploma/Certificate:
      </span>
   </p>
</div>
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement