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粉3302320962024-02-22 17:27:04
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>