我尝试编写一个函数,该函数接收用户关于在表单中创建多少字段的输入。然后该函数创建一个包含文本框数量(相当于用户输入)和一个提交按钮的表单。我写了这个函数,但它似乎没有在我出错的地方工作。如果有人可以帮助我,我将不胜感激。我的代码:
function createTextBox()
{
var box=document.getElementById('pop'); //getting the ID of the containner
var val=document.getElementById('uValue').value; //getting the Input value from the user
var candidateForm=document.createElement('form'); //Creating a form and giving the attributes
candidateForm.name="candidateForm";
candidateForm.method="post";
candidateFomr.action="process.php";
for(var i=0; i<val;i++)
{
var newTextbox = document.createElement('input'); //creating the textboxes according to the users input
newTextbox.type="textbox";
newTextbox.name="candidate[]";
newTextbox.id="candidateId";
candidateForm.appendChild(newTextbox); //putting the created textboxes in the form
}
var saveButton=document.createElement('input'); //creating the submit button which when clicked will save the value written in the textboxes
saveButton.type="submit";
saveButton.name="submitButton";
saveButton.value="Enter";
candidateForm.appendChild(saveButton); //putting the submit button in the form
box.appendChild(candiateForm); //And putting the form in the containner.
//alert (val);
}
这是HTML部分
<body>
<input type="textbox" name="value_box" id="uValue" ></input>
<input type="button" onclick="javascript:createTextBox()" value="Click"></input>
<div id="pop"></div>
</body>
提前致谢