Apologies my experience with html and javascript is limited so I am trying to figure out the best way to do this. Essentially I am dealing with some html that creates a form for users to send messages. The form allows the selection of the subject and text to be input.
<td>Subject</td>
<td>
<select id="subject">
<option selected="selected" value="none">Please select a subject</option>
{% for subject in MESSAGE_SUBJECTS %}
<option value="{{subject}}">{{subject}}</option>
{% endfor %}
</select>
<!-- <input type="text" id="subject" size="80" value='No Subject' onfocus="if(this.value==this.defaultValue)this.value='';" name="subject" /> -->
</td>
</tr>
<tr>
<td>Message</td>
<td><textarea id="newmessage" cols="80" rows="6"
onfocus="if(this.value==this.defaultValue)this.value='';"
name="newmessage">Please type your message here</textarea></td>
</tr>
Without going into too much detail the subjects are just a series of strings. For the purposes of this we can just call them ‘sub1’ and ‘sub2’. I want to make it so the textarea only appears when ‘sub1’ is selected from the dropdown list.
I believe a javascript event handler is the way to go here and there is an associated javascript file with some functions but I can’t figure out what the syntax would look like. I assume it is something like:
function conditionalMessage() {
if( subject == "sub2" ) {
//some code that defines displaying text to explain now message can be sent with this subject
} else {
//some code that displays the message box as it currently does
}
Is this a case of defining the message box and the text response as divs and then calling the divs?
This is a Django based system.
Thanks for any and all help