2014-04-29 37 views
0

好吧我對JS非常陌生,人們一直在幫助我,但是我在創建一個包含多個輸入元素的表單時遇到了問題。第二個元素出現,但第一個元素填充input.value從第二個元素,我沒有在第二個值JavaScript無法創建多個輸入

我以前沒有使用DOM函數,所以我可能會搞砸我是怎麼樣稱他們。任何幫助是極大的讚賞

newWindow = window.open("", null, "height=200,width=400,status=yes,toolbar=no,menubar=no,location=no"); 


newWindow.document.title = "Info Window"; 


// create a form and set properties 
var form = document.createElement('form'); 
form.action = 'http://google.com'; 
form.method = 'post'; 

// insert into the body of the new window 
newWindow.document.body.appendChild(form); 

// add text before the input 
var cNumLab = document.createElement('cNumLab'); 
form.appendChild(document.createTextNode('Craft Number:')); 

// add a text input 
var input = document.createElement('input'); 
input.type = 'text'; 
input.name = 'input'; 
input.value = 'Enter Craft Number Here'; 
form.appendChild(input); 

//add linebreak 
var linebreak = document.createElement('br'); 
form.appendChild(linebreak); 

// add text before the input 
var sDescL = document.createElement('sDescL'); 
form.appendChild(document.createTextNode('Short Desc:')); 

// add a text input 
var sDesc = document.createElement('input'); 
input.type = 'text'; 
input.name = 'sDesc'; 
input.value = 'Enter Short Description Here:'; 
form.appendChild(sDesc); 

回答

2

在你的第二個「輸入」變量引用的第一場「輸入」,而不是後來的「SDESC」

應該

// add a text input 
var sDesc = document.createElement('input'); 
sDesc.type = 'text'; 
sDesc.name = 'sDesc'; 
sDesc.value = 'Enter Short Description Here:'; 
form.appendChild(sDesc);