2010-07-14 18 views

回答

0

這裏是一個可以說明這樣做的一種方式的示例:

<html> 
<head> 
<script> 
var messages = ['Message 0', 'Message 1', 'Message 2', 'Message 3', 'Message 4']; 
function myOnChangeHandler(selectObj) { 
    // if there are more elements with name="additional_info" then you should attach unique id to your text area and use getElementById instead 
    var textAreaElement = document.getElementsByName("additional_info")[0]; 
    textAreaElement.value = messages[selectObj.selectedIndex]; 
} 

</script> 
</head> 
<body> 
<form> 
<select id="continent" onchange="myOnChangeHandler(this);"> 
    <option value="0">Select a Continent</option> 
    <option value="1">North America</option> 
    <option value="2">South America</option> 
    <option value="3">Asia</option> 
    <option value="4">Europe</option> 
    </select> 
    Additional info: 
<textarea cols="80" rows="8" style="" name="additional_info"></textarea> 
</form> 
</body> 
<html> 

希望這有助於!

+0

這似乎已經完成了技巧謝謝,現在唯一的問題是值是字符串,它將根據錯誤的狀態而改變。我會嘗試做一個開關案例或使用elsif語句爲每個狀態輸出正確的消息。 再次感謝 – user379222 2010-07-14 15:14:48

相關問題