Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在jsp程序中使用javascript添加表单字段?_Javascript_Mysql_Jsp - Fatal编程技术网

在jsp程序中使用javascript添加表单字段?

在jsp程序中使用javascript添加表单字段?,javascript,mysql,jsp,Javascript,Mysql,Jsp,基本上,我有一个javascript函数,允许用户根据自己的意愿添加表单。我有几个输入字段,添加它们没有问题。这是我的密码 <script> var counter = 1; function addInput(divName){ var newdiv = document.createElement('div'); newdiv.innerHTML = "<center><br>

基本上,我有一个javascript函数,允许用户根据自己的意愿添加表单。我有几个输入字段,添加它们没有问题。这是我的密码

<script>

var counter = 1;

function addInput(divName){
          var newdiv = document.createElement('div');
          newdiv.innerHTML =         
          "<center><br><hr width='300'>\n\
                   Control Number: <br><input type='text' name='control_number'>\n\
                   Date of Pull Out: <br><br><input type='date' name='pulloutdate'>\n\
                \n\Item Description: <br><br> <select name='des'>\n\
                \n\
                   <%  while(rSelectRecord.next()){ %>
         <option value="<%=rSelectRecord.getString("item_code")%>"><%=rSelectRecord.getString("item_code")%></option>
          <% } %>
</center>";
          document.getElementById(divName).appendChild(newdiv);
          counter++;
}

</script>

var计数器=1;
函数addInput(divName){
var newdiv=document.createElement('div');
newdiv.innerHTML=
“

\n\ 控制编号:
\n\ 退出日期:

\n\ \n\项目说明:

\n\ \n\ "; document.getElementById(divName).appendChild(newdiv); 计数器++; }
但是,在innerHTML中,项目描述中的值应该取自我创建的数据库。我想这样做,在里面放一张小纸条,得到我的价值观。它不起作用


是否有任何方法可以添加从数据库中选择的表单并将其放入javascript函数中?或者有没有一种方法可以在不同的页面中创建表单,并将其包含在我的newdiv.innerHTML=“filenamehere”中?请帮忙?谢谢

你所做的应该有用。我认为您的scriptlet只是在向javascript字符串中添加未替换的换行符,并将其破坏。那么,试试这个:

            \n\
               <%  while(rSelectRecord.next()){ %>\
     <option value='<%=rSelectRecord.getString("item_code")%>'><%=rSelectRecord.getString("item_code")%></option>\
      <% } %>\
        \n</select>\n\
</center>";
\n\
\
\
\
\n\n\
";

Hi,我尝试过这个,但它不起作用。当出现scriplet时,它不会再添加任何表单。如果scriptlet没有抛出错误,它应该会起作用。我一直都在这样做。若要调试它,请尝试从
newdiv.innerHTML=
语句中删除所有换行符。将所有换行符放在一行并平衡引号应该可以让它正常工作如果要嵌套,请确保交替使用双引号和单引号(请参阅更新的答案)。