I am developing a little website with webflow and must now write a tiny bit of custom code. To simplify and summ up, I have a checkbox that is outside fo the form tag. My goal is to write a little jquery of javascript code to "capture" the checkbox outside the form tag and add it to the form submission.
Here is what I came up with, but it's still not working. Would you have an idea ? I'm pretty new to code... thank you :)
The script I would love to use: (if that makes sense?)
<script>
// defines the variable for the form
var form = document.getElementById("reservation");
// add the checkbox with the id of "outsider" to the form submission
document.getElementById("outsider").addEventListener("click", function () {
form.submit();
});
</script>
EDIT: I made some research before of course, but couldn't really understand the code snipet people were talking about and how to "link" the script to the actual submit button of my form.
For modern browser:
var checkedValue = document.querySelector('.outsider:checked').value;
By using jQuery:
var checkedValue = $('.outsider:checked').val();
Pure javascript:
var checkedValue = null;
var inputElements = document.getElementsByClassName('outsider');
for(var i=0; inputElements[i]; ++i){
if(inputElements[i].checked){
checkedValue = inputElements[i].value;
break;
}
}
Another javascript: Again, not sure how to link the function to my submit button
CheckboxHandler.isChecked = function (checkboxObj) {
return(checkboxObj.checked == true);
};