How can i get radio value of true or false


function sendMail(params){
		var tempparams ={
			from_name:document.getElementById("InputName").value,
			last_name:document.getElementById("InputLastname").value,
			pick_up:document.getElementById("shippingOption1").value,
			delivery:document.getElementById("shippingOption2").value,
			addressone:document.getElementById("address").value,
			addresstwo:document.getElementById("address2").value,
			total:document.getElementById("total").innerText
		}
		emailjs.send(`service_mvduipb`,`template_8cr649h`,tempparams)
		.then(function(res){
			  console.log("success",res.status)
			  })
	}
	
<div class="custom-control custom-radio">
                                        <input id="shippingOption2" name="shipping-option" class="custom-control-input" type="radio" value="2">

<div class="custom-control custom-radio">
                                        <input id="shippingOption1" name="shipping-option" class="custom-control-input" checked="checked" type="radio" value="1">
                                        <label class="custom-control-label" for="shippingOption1">

<div class="custom-control custom-radio">
                                        <input id="shippingOption1" name="shipping-option" class="custom-control-input" checked="checked" type="radio" value="1">
                                        <label class="custom-control-label" for="shippingOption1">

when I receive the email that I send I receive the value of 1 or 2 my question is how can i set it to true or false and i get 1 or 2 regardless if its checked or not
ps. and if i remove the value i get both off at least i want the checked button to be on not both

Could you be more specific? It’s not clear to me what you mean. As far as “getting the value”, is this what you want?

<div class="custom-control custom-radio">
  <input id="shippingOption2" name="shipping-option" class="custom-control-input" type="radio" value="2">
  <label class="custom-control-label" for="shippingOption2">button 2</label>
</div>

<div class="custom-control custom-radio">
  <input id="shippingOption1" name="shipping-option" class="custom-control-input" checked="checked" type="radio" value="1">
  <label class="custom-control-label" for="shippingOption1">button 1</label>
</div>

<button onclick="console.log('button 1 is checked?', getElementById('shippingOption1').checked);">submit</button>

tried my best now
hope you can see my code better i posted the whole js fille

Please don’t add to threads by editing previous posts - it makes it very confusing to follow.

I guess I’m confused what you want. With this HTML:

<div>
  <input id="shippingOption2" name="shipping-option" type="radio" value="2">
  <label for="shippingOption2">button 2</label>
</div>

<div>
  <input id="shippingOption1" name="shipping-option" checked="checked" type="radio" value="1">
  <label for="shippingOption1">button 1</label>
</div>

<button onclick="handleSubmit();">submit</button>

and this JS:

const handleSubmit = () => {
  console.log('button 2 is checked', document.getElementById('shippingOption2').checked)
  console.log('button 1 is checked?', document.getElementById('shippingOption1').checked)
}

I can read the states of those buttons. You can see it work in this pen.

What is this not doing that you want to do?

I’m equally confused as @kevinSmith, but my guess is that you want to get values for both radio buttons when you receive the form data.

If that’s the case - that’s not possible. If a form is submitted, the only thing that gets transferred to the server is the value of the checked radio button together with the name. In your case, shipping-option=1 (or 2). Any data concerning the unchecked inputs isn’t sent to the server. If no radio button is checked, nothing about those inputs is sent.

Read more here: <input type="radio"> - HTML: HyperText Markup Language | MDN

1 Like

I want so when i press submit button i recive output of value off or on deepens if it checked or not or some type of value not just on

Cuz right now i only get on on both radio buttons as output even tho one of them is checked i want so that so the output be recognizable when its checked

Yeah that’s explained in the article I linked above:

Thanks for your help, I had a similar problem

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.