폼에서 작성할 필드 수에 관해서 사용자로부터 입력을받는 함수를 작성하려고했습니다. 그런 다음이 함수는 텍스트 상자와 사용자가 제출 한 숫자의 숫자 (사용자 입력과 동일)를 포함하는 Form을 만듭니다. 나는 함수를 썼다. 그러나 내가 잘못한 곳에서는 작동하지 않는 것 같다. 어느 누구라도 나를 도울 수 있다면 감사 할 것입니다. 내 코드 : 여기자바 스크립트로 양식을 동적으로 작성하기
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);
}
는
<body>
<input type="textbox" name="value_box" id="uValue" ></input>
<input type="button" onclick="javascript:createTextBox()" value="Click"></input>
<div id="pop"></div>
</body>
감사합니다 사전에 HTML 부분입니다 : D
또한 변경에 HTML을 변경
그것의 작동하지 않는 이유는 잘 모릅니다 작동하지 않습니다. : – Chakra
** 어떻게 작동하지 않습니까? 어떻게됩니까? – SLaks
val이 숫자인가요? 아마도 5 대신에 "5"와 같은 문자열 일 수 있습니다. var val = + document.getElementById ('uValue') .value – Azder