0

I have a html radio button, but I want to know how can I get a value from it. (I'm working on Electron)

Here is my Radio code

 <label class="container">Ne plus afficher cette page au lancement.<input type="checkbox" unchecked="uncheck"><span class="checkmark"></span>

Basically I want to call a funtion if the box is checked.

for exemple

Function typeFunction(){

//load a window (Not sure if this is right
  mainWindow.loadFile('index.html')

}
Aniket G
  • 3,471
  • 1
  • 13
  • 39
  • 3
    You say you are working with a radio button, but your code shows a checkbox. You also have invalid HTML with the `unchecked` attribute. Next, you say you want the value, but then you say that you want to know if it is checked. Then, you show invalid JavaScript with `Function`, rather than `function`. Please update your question to be more concise. – Scott Marcus Mar 17 '19 at 23:18
  • Possible duplicate of [How can I check if a checkbox is checked?](https://stackoverflow.com/questions/9887360/how-can-i-check-if-a-checkbox-is-checked) – Aniket G Mar 17 '19 at 23:18
  • To get a value from a check box or radio button, it must have a `value` attribute. You are missing this from your code sample. – Jon P Mar 18 '19 at 03:25

2 Answers2

0

First, you need to remove that unchecked tag its useless. Secondly, give a class to the checkbox for example " checkButton ". Lastly, you need to select the Item from the DOM.

const checkBtn = document.querySelector('.checkButton');

If you want to DO something when the checkbox is checked you just need to use the .checked property ->

 if(checkBtn.checked) {
 // do something 
} else {
 // do something else 
 }

Also use function because if you are gonna use it with capital ,,F'' JS is gonna think this is a function constructor.

Kristian
  • 72
  • 2
  • 6
  • A constructor function is just a regular function (lower case "f") that is called with the `new` keyword. You might be referring to using the "function constructor" (rather than a constructor function), which is `var myFunc = new Function("body here");`. – Scott Marcus Mar 18 '19 at 01:22
0

Give ids to each choice.

id="choice1"

Then get the value by referring to the said id. choice1.value

aaron lilly
  • 274
  • 1
  • 14