1

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");
 });
  • So you want the enter key to act like a tab key? – epascarello Oct 23 '14 at 20:19
  • `event.preventDefault();` – APAD1 Oct 23 '14 at 20:21
  • Yes, exactly! Basically, I want the user first to submit a subject/title and then press tab or enter and populate his question form, and finally hit the submit button. As of now, the tab button does that, but the ENTER prematurely listens to the submit click. –  Oct 23 '14 at 20:25

0 Answers0