+ 3

How do I get the values of a cheakbox into a js function when the form is submitted?

I want to get the values of the options clicked in the cheakbox input into a JavaScript function. How do I do that?

14th Jun 2018, 1:42 PM
LELOUCH
LELOUCH - avatar
3 ответов
+ 2
For modern browsers: var checkedValue = document.querySelector('.messageCheckbox:checked').value; By using jQuery: var checkedValue = $('.messageCheckbox:checked').val(); Pure javascript without jQuery: var checkedValue = null; var inputElements = document.getElementsByClassName('messageCheckbox'); for(var i=0; inputElements[i]; ++i){ if(inputElements[i].checked){ checkedValue = inputElements[i].value; break; } } https://stackoverflow.com/questions/11599666/get-the-value-of-checked-checkbox
14th Jun 2018, 1:49 PM
Alexander Sokolov
Alexander Sokolov - avatar
+ 2
https://code.sololearn.com/WCfZ2lZpFXwx/?ref=app
15th Jun 2018, 2:03 AM
Calviղ
Calviղ - avatar
+ 1
Alexander Sokolov is this messagecheakbox a class name you added or a keyword?
14th Jun 2018, 1:54 PM
LELOUCH
LELOUCH - avatar