5
function addrow() {

    document.getElementById("myTableData").style.display="block";
    /*displaying div on click of button  abc*/

      var el = document.createElement('input');
          el.type = 'text';
          el.name = 'kname';
    /*creating name field*/

      var el_r = document.createElement('input');
          el_r.type = 'radio';
          el_r.name = 'gender';
          el_r.value ='FEMALE';
          el_r.id = "rad1";  
          el_r.defaultChecked = true;   
         /* creating radio button for gender field */  

      var el_r2 = document.createElement('input');
              el_r2.type = 'radio';
          el_r2.name = 'gender';
          el_r2.value ='MALE';
          el_r2.id = "rad2";  
        /* creating radio button for gender field */  

       var obj1 = document.createTextNode("Female");  
       var obj2 = document.createTextNode("Male");  

       var objLabel = document.createElement("label");  
        objLabel.htmlFor = el_r.id;  
        objLabel.appendChild(el_r);  
        objLabel.appendChild(obj1);

       var objLabel2 = document.createElement("label");  
        objLabel2.htmlFor = el_r2.id;  
        objLabel2.appendChild(el_r2);  
        objLabel2.appendChild(obj2);  

 /* creating drop down for date field */  
       var el_s = document.createElement('select');
           el_s.onchange =  function(){ 
           var r = el_s.options[el_s.selectedIndex].value;
            alert("selected date"+r); //cheking the selected date value;
            }
      for(var i=0;i<32;i++)
      {
         var j = i;
         j = document.createElement('option');
          j.text=i;
          j.name="day";
          j.value=j;
          el_s.appendChild(j);
      }


      var month = new Array("January","Februray","March","April","May","June","July","August","September","October","November","December");
      var el_sm = document.createElement('select');
      for(var i=0;i<month.length;i++)
      {
         var j = i;
          j = document.createElement('option');
          j.text=month[i];
          j.name="month";
          j.value=month[i];
          el_sm.appendChild(j);
      }

      var el_sy = document.createElement('select');
      for(var i=2013;i>1950;i--)
      {
         var j = i;
          j = document.createElement('option');
          j.text=i;
          j.name="year";
          j.value=j;
          el_sy.appendChild(j);
      }



    var table = document.getElementById("myTableData");
    var tableBody = document.createElement('TBODY');
    table.appendChild(tableBody);

       var tr = document.createElement('TR');
       tableBody.appendChild(tr);

           var td = document.createElement('TD');
           td.width='175';
           td.appendChild(el);
           tr.appendChild(td);

           var td = document.createElement('TD');
           td.width='245';
           td.appendChild(objLabel);
           td.appendChild(objLabel2);
           tr.appendChild(td);

           var td = document.createElement('TD');
           td.width='245';
           td.appendChild(el_s);
           td.appendChild(el_sm);
           td.appendChild(el_sy);
           tr.appendChild(td);

          myTableData.appendChild(table);

}
</script>
<input type="submit" value="submit"/>

我在名为 abc 的按钮单击时借助 javascript 在 HTML 中动态生成表单。我的代码工作正常,当我插入值时,但是当我在按钮的帮助下发布此表单时,值名称和性别显示在地址栏中,但 DATE(元素名称“el_s”)选择的值未显示在地址栏。有 2 个按钮首先显示显示表单的 div,下一个是表单的提交按钮

4

1 回答 1

0

您必须设置el_s.name='date'才能自动发布数据。

于 2013-09-06T22:54:43.417 回答