HTML buttons and their corresponding values
P粉710478990
P粉710478990 2024-02-21 21:48:59
0
1
518

I'm a backend developer, so I need help with this frontend part.

<input id="entered_value" type="number" name="entered_value">
<input id="entered_valuetwo" type="text" name="entered_valuetwo">
<select id="selected_value" name="selected_value"> <option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<button type="button" id="send-data">点击我</button>

When the button is clicked, it already triggers something in my JS. But, the best way is how to pass "entered_value", "entered_valuetwo" and "selected_value" to button at the same time and then they are passed to js function.

P粉710478990
P粉710478990

reply all(1)
P粉330232096

just add this to your js

document.getElementById('send-data').addEventListener('click',buttonFunction)
function buttonFunction(){

let enteredValue = document.getElementById('entered_value').value
let enteredValue2 = document.getElementById('entered_valuetwo').value
let selectValue = document.getElementById('selected_value').value

console.log(enteredValue,enteredValue2,selectValue)

}
<input id="entered_value" type="number" name="entered_value">
<input id="entered_valuetwo" type="text" name="entered_valuetwo">
<select id="selected_value" name="selected_value"> <option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<button type="button" id="send-data">Click me</button>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template