views:

15

answers:

1

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?

A: 

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!

draganstankovic
That seems to have done the trick thanks, the only problem now is that the values are strings which will change depending on the status of the bug. I will try do a switch case or use if elsif statements to output the correct message for each status.Thanks again