Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

156
Views
How to display the item selected on the same screen after the form is Submitted by the User

I'm trying to display the item selected on the same screen after the form is submitted by the user. The problem is when I use type="button" for the button instead of type="submit" then the required attribute is not checked. Is there a way to display the items selected after the form is submitted and the required attribute is also checked using JavaScript?

required

Suppose when you press the submit button without checking any radio buttons, an error is displayed because of the required attribute, and when the user checks any of the options, then after pressing the submit button, the value is displayed adjacent to the inputs.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

  • You can e.preventDefault() on your onSubmit handler to prevent the default page reload on form submission.

  • Then use the FormData object to get the value you require.

const form =  document.querySelector('#form')

form.onsubmit = (e) => {
  e.preventDefault()
  const data = new FormData(e.target);
  document.querySelector('#output').innerHTML = data.get('drone')
}
<form id='form'>

  <fieldset>
      <legend>Select a maintenance drone:</legend>

      <div>
        <input type="radio" id="huey" name="drone" value="huey"
                required>
        <label for="huey">Huey</label>
      </div>

      <div>
        <input type="radio" id="dewey" name="drone" value="dewey">
        <label for="dewey">Dewey</label>
      </div>

      <div>
        <input type="radio" id="louie" name="drone" value="louie">
        <label for="louie">Louie</label>
      </div>
  </fieldset>
  
  <button type='submit'>Submit</button>
</form>

<div id="output"/>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!