How to use JavaScript to dynamically update the Bugzilla Additional Comments textarea?

大城市里の小女人 提交于 2019-12-25 03:07:58

问题


I am customising Bugzilla and I need to update the text in the Additional Comments text area on the bug editing page. This text will need to be changed dynamically depending on which status the user selects from the drop down menu. For this im hoping to use the onChange event. Has anyone any suggestions on how to implement this?


回答1:


Here is an example that may illustrate one way of doing it:

<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>

Hope that this helps!



来源:https://stackoverflow.com/questions/3246224/how-to-use-javascript-to-dynamically-update-the-bugzilla-additional-comments-tex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!