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 :
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>