I have the following HTML code for a user to enter a question with a subject:
<form class="cf" id="question-form">
<h2>Welcome to <span>My Website</span>!</h2>
<p>Enter a subject and question to get started.</p>
<div>
<input type="text" name="subject" placeholder="Subject" />
</div>
<div>
<textarea rows="5" cols="40" name="question"
placeholder="Question"></textarea>
</div>
<input type="submit" class="btn" value="Submit" />
</form>
I have an text input form for the subject of the question, and I have the 'textarea' element for the question itself. I want to add an event listener to listen to the 'submit' button after both the subject form and the question forms, and handles the event before the user can enter a question. However with the following JavaScript code, the code 'listens' to the ENTER key pressed in the subject form. I want to enter some subject test, press the enter key, put some text in the question text, and then click the submit button.
var questionForm = rightPane.childNodes[1];
questionForm.addEventListener("submit", function(event) {
// do something
alert("I have been clicked");
});