需要在javascript中创建动态表单

时间:2016-02-23 09:43:33

标签: javascript php jquery html

我尝试在javascript中创建动态字段。我创建简单的文本框它工作正常。我想显示div标签,需要用javascript创建selectbox。我想在javascript中创建下面给出的表单



<form method="POST">
  <table border=1> 
    <tr>
      <td>
       <div class="col-md-6">
          <div class="form-group">
	<label class="control-label col-md-4">First  Name:</label>
	<div class="col-md-8">
                    <input type="text" name="V1_Fname" >
           
               </div>
           </div>
       </div>
     </td>
     <td>
       <div class="col-md-6">
          <div class="form-group">
	<label class="control-label col-md-4">Last   Name:</label>
	<div class="col-md-8">
                     <input type="text" name="V1_Lname" ">
                 </div>
           </div>
       </div>  
      </td>
   </tr>
   <tr>
      <td>
       <div class="col-md-6">
          <div class="form-group">
	     <label class="control-label col-md-4">Relation to Member:</label>
	       <div class="col-md-8">
                    <select size="1" name="V1_Relation">
          	     <option selected="selected"></option>
      	     <option value="SP">Spouse</option>
      	     <option value="Son">Son</option>
       	     <option value="Daughter">Daughter</option>
      	     <option  value="F">Father</option>
     	     <option   value="M">Mother</option>
        	    <option value="MIL">Mother-in-   value="OTH">Other</option>
         	  </select>
           
               </div>
           </div>
       </div>
     </td>
     <td>
      
      </td>
   </tr>

</table>
</form>
&#13;
&#13;
&#13;

我在javascript中尝试了名字,姓氏和年龄。

function create(sel_value) {
  // alert(sel_value);
  for (var i = 1; i <= sel_value; i++) {
    $("div#form1").slideDown('slow');
    $("div#form1").append($("#form_submit").append($("<div/>", {
      id: 'head'
    }).append($("<h3/>").text("Visitor" + i)), $("<input/>", {
      type: 'text',
      placeholder: 'Name' + i,
      name: 'firstName_' + i
    }), $("<br/>"), $("<input/>", {
      type: 'text',
      placeholder: 'Last Name' + i,
      name: 'lastName_' + i
    }), $("<br/>"), $("<input/>", {
      placeholder: 'Age' + i,
      type: 'text',
      name: 'Age_' + i
    }), $("<br/>"), $("<hr/>"), $("<br/>")))
  }
}

0 个答案:

没有答案