生成的Javascript表单未提交

时间:2016-05-19 16:36:38

标签: javascript php jquery html forms

我在使用Javascript生成时将表单的数据提交到php文件时遇到问题。不太确定如何解决它。它在测试.html文件中通过它自己工作,但是当javascript使用它时 所以php看起来像这样:

function logDisp(){
var divCheck = document.getElementById('logRec');
if (divCheck != null) divCheck.parentNode.removeChild(divCheck);

var getC = document.getElementById("craneDrop");
var vCrane = getC.options[getC.selectedIndex].text;

var getD = document.getElementById("dept");
var vDept = getD.options[getD.selectedIndex].text;

var logDiv = document.createElement("div");
logDiv.setAttribute("id", "logRec");
logDiv.className = "round1";
logDiv.style.marginTop = "10px";
logDiv.style.width = "600px";

logDiv.innerHTML = "<table border=1 width=100% style='margin-top:20px;'>"
+"<form action='submit.php' method='post' name='form1' id='form1'>"
+"<tr><td>Department | <input type=text name=lname value='"+vDept+"' disabled></td><td colspan=2> Crane | <input type=text name=fname value='"+vCrane+"' disabled></td></tr>"
+"<tr><td align=center bgcolor=black colspan=3>Controls</td></tr>"
+"<tr><td bgcolor=black ></td><td bgcolor=black>(S) atisfactory</td>"
+"<td bgcolor=black>(U) n-Satisfactory</td></tr>"

+"<tr><td>Pendant (Overall Condition)</td>"
+"<td><input type=radio name=r1 value=s checked=checked></td>"
+"<td><input type=radio name=r1 value=u></td></tr>"

+"<tr><td>Test Operational Controls</td>"
+"<td><input type=radio name=r2 value=s checked=checked></td>"
+"<td><input type=radio name=r2 value=u></td></tr>"

+"<tr><td>Proper Markings</td>"
+"<td><input type=radio name=r3 value=s checked=checked></td>"
+"<td><input type=radio name=r3 value=u></td></tr>"

+"<tr><td colspan=3 align=center bgcolor=black>Operation</td></tr>"

+"<tr><td>Unusual Noises</td>"
+"<td><input type=radio name=r4 value=s checked=checked></td>"
+"<td><input type=radio name=r4 value=u></td></tr>"

+"<tr><td>Hoist Travel</td>"
+"<td><input type=radio name=r5 value=s checked=checked></td>"
+"<td><input type=radio name=r5 value=u></td></tr>"

+"<tr><td>Trolley Travel</td>"
+"<td><input type=radio name=r6 value=s checked=checked></td>"
+"<td><input type=radio name=r6 value=u></td></tr>"

+"<tr><td>Brake(s)</td>"
+"<td><input type=radio name=r7 value=s checked=checked></td>"
+"<td><input type=radio name=r7 value=u></td></tr>"

+"<tr><td colspan=3 align=center bgcolor=black>Chain Hoist</td></tr>"

+"<tr><td>Hoist Chain</td>"
+"<td><input type=radio name=r8 value=s checked=checked></td>"
+"<td><input type=radio name=r8 value=u></td></tr>"

+"<tr><td>Limit Switches</td>"
+"<td><input type=radio name=r9 value=s checked=checked></td>"
+"<td><input type=radio name=r9 value=u></td></tr>"

+"<tr><td>Chain Basket</td>"
+"<td><input type=radio name=r10 value=s checked=checked></td>"
+"<td><input type=radio name=r10 value=u></td></tr>"

+"<tr><td colspan=3 align=center bgcolor=black>Hook</td></tr>"

+"<tr><td>Visial Appearance</td>"
+"<td><input type=radio name=r11 value=s checked=checked></td>"
+"<td><input type=radio name=r11 value=u></td></tr>"

+"<tr><td>Opening less than 10%</td>"
+"<td><input type=radio name=r12 value=s checked=checked></td>"
+"<td><input type=radio name=r12 value=u></td></tr>"

+"<tr><td>Condition of Saddle</td>"
+"<td><input type=radio name=r13 value=s checked=checked></td>"
+"<td><input type=radio name=r13 value=u></td></tr>"

+"<tr><td>Bend or twist exceeding 0%</td>"
+"<td><input type=radio name=r14 value=s checked=checked></td>"
+"<td><input type=radio name=r14 value=u></td></tr>"

+"<tr><td colspan=3 align=center bgcolor=black>Other</td></tr>"

+"<tr><td>Loose Parts</td>"
+"<td><input type=radio name=r15 value=s checked=checked></td>"
+"<td><input type=radio name=r15 value=u></td></tr>"

+"</table>"
+"Member number:<BR><input type=text name=member><BR>"
+"Date:<BR><input type=text name=inputDate value="+dateIn()+"><BR>"
+"<BR><input type=submit />"
+"</form>";
logDiv.innerHTML += "<BR>";

var getOk = document.getElementById("craneDrop");
var vOk = getOk.options[getOk.selectedIndex].value;

if(vOk != '0') // Check if crane selection is a valid selection
document.getElementById("log").appendChild(logDiv);

}

并将其附加到HTML:

<div id='log' style='padding-bottom: 20px;'></div>

如何在初始页面生成后将其数据提交给submit.php?

2 个答案:

答案 0 :(得分:0)

在追加你的html后添加:

<强>的Javascript

document.getElementById('form1').submit();

答案 1 :(得分:0)

表单可以包含整个表。表格单元格可以包含整行。表格不能存在于表格内,而是存在于该表格中的一组单元格中。这可能是答案吗? - Algernop K。