简体   繁体   中英

I want the "submit" button to check users input and display "right" or "wrong" to the user

<form
        class="triviaQuestions"
        action="/submitquestion1"
        method='GET'
    >
    <div>
        <label for="questionOne"><h4 style="text-align: center; 
font-family:Verdana, Geneva, Tahoma, sans-serif;" >Question 1</h2>
        <p class=questions>
            What is the speed of sound?
            <br>a)120km/h &nbsp; b)1,200 &nbsp; km/h &nbsp; 
c)400km/h &nbsp; d)700km/h
        </p>
    </label>
        <input type="text"
            name="qOneAnswer"
            class="textarea"
            placeholder="Enter your answer"
            size="200"
            required/>

        <input type="submit" value="SUBMIT" class="submitBtn" />
    </div>
</form> 

This is my HTML code

Also I have initialized my express, I just need help writing a code to process users input once submit button clicked and to display whether they got the correct answer/input or not.

const express = require("express");
const ejs= require("ejs");
const app = new express();

app.use(express.json());
app.use(express.urlencoded({extended:true}));
  1. Firstly You Would Need to Parse the Data Coming to The Server.
  2. Setup a route (exactly what you have defined in the action value of the form) on the Express Server using app.get()
  3. Use the Req.params object to get the entered value
  4. Check if it is correct or not
  5. Render or Redirect using res.render or res.redirect accordingly

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM