Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

access value attribute data

I have the below form suppose I choose the first option. I want to ask is There a way to access value =0 and converted to number rather than A if the form submitedd

    <form  id="rpoerForm" action="http://localhost:5000/result" class="form"  method="post" >
        <div class="form__input-group">
           <label for="City">Select city</label>
   <select name="City" id="City" class="Input">
            <option value='0'>A</option>
            <option value='1'>B</option>
            <option value='2'>C</option>
            <option value='3'>D</option>
            <option value='4'>E</option>
            <option value='5'>F</option>
      </select>  

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Try this, onsubmit you will receive an array with the values of all inputs/select inside the form inside a tuple with the shape ["name", value] :

rpoerForm.onsubmit = e => {
  e.preventDefault()
  const data = [...new FormData(e.target).entries()].map(entry => [entry[0], +entry[1]])
  console.log(data)
}
<form id="rpoerForm" action="http://localhost:5000/result" class="form" method="post">
  <div class="form__input-group">
    <label for="City">Select city</label>
    <select name="City" id="City" class="Input">
      <option value='0'>A</option>
      <option value='1'>B</option>
      <option value='2'>C</option>
      <option value='3'>D</option>
      <option value='4'>E</option>
      <option value='5'>F</option>
    </select>
    <button>Submit</button>
</form>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading