0

I am a backend developer so I need help with this front end 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">Click me</button>

when the button is clicked its already triggering something I have in JS. But what is the best way to pass "entered_value" & "entered_valuetwo" & "selected_value" all 3 at the same time to the button and they get passed to the js function thereafter.

2 Answers 2

1

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>

Sign up to request clarification or add additional context in comments.

Comments

0

If you want to put it into a databas i would use post request like this:

<form action="your url" method="Post">
  <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>
</form>

But if you want to use it temporarylie use document.getElementby(𝗜𝗗) or better document.querySelector(#𝗜𝗗)

2 Comments

this doesn't make any sense. he wants the data in his js code
@DCR if he wants to save the file if you reload the website, this type of code is the best option for the front end

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.