+ 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?
3 odpowiedzi
+ 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
+ 2
https://code.sololearn.com/WCfZ2lZpFXwx/?ref=app
+ 1
Alexander Sokolov is this messagecheakbox a class name you added or a keyword?