2016-07-04 85 views
0

我通常編程java,但開始編程javascript和我搜索和搜索,但找不到任何工作。我的問題是,有4個輸入字段(PARID,Groups,Customer和Projectname),我想將它們的值加在一起做成一個大字符串,例如:123456_NEC_Franzi_Seestadt,但每次我試圖獲得警報時,它只是讓我說「未定義」Javascript(with Sharepoint 2007)alert

<p> 
Par ID: 
<input id = "PARID"> 
</p> 
<p> 
Research Group: 
<select id = "Groups"> 
    <option></option> 
    <option>BAM</option> 
    <option>PAS</option> 
    <option>AVT</option> 
    <option>SRA</option> 
    <option>NEC</option> 
    <option>ITP</option> 
    <option>ELD</option> 
    <option>RFT</option> 
    <option>SEE</option> 
</select> 
</p> 
<p> 
Customer: 
<input id = "Customer"> 
</p> 
<p> 
Projectname: 
<input id = "Projectname"> 
</p> 
<p> 
Submit: 
<input id = "Submit" type = "button" value = "Submit" onclick = "output()"> 
</p> 

<script> 
function output() { 

    var w, text; 

    // alert ("did it work?"); 

    document.getElementById("PARID").value = w; 

    if (w != null) { 
     alert(w); 
     } 


    } 
</script> 
+1

您必須編寫'w = document.getElementById(「PARID」).value;'而不是! – cFreed

回答

0

document.getElementById("PARID").value = w;

應該

w = document.getElementById("PARID").value;

變量賦值是南轅北轍。這只是一個邏輯錯誤,沒有任何特定的Javascript。

P.S.如果要合併不同字段的值,可以使用+運算符將它們連接成單個字符串。