mercredi 1 avril 2020

Jquery form submit button goes to URL based on checkbox selected

I have a simple contact form with multiple checkboxes, when a user selects a checkbox it should go to the url/folder tied to the url that's in the value. The current problem is after a user checks the checkbox and clicks submit, then goes back to that page and the checkbox resets, the submit button still takes them to the previously selected checkbox.

Need a way to fully reset the form and disable the button so the submission doesn't get too confusing for the user. Thanks!

Here is my form code:

<code>
`<form name="frm" id="myForm" method="post" >`
`<div class="provider-checkboxes">`
`<input type="checkbox" name="rGroup" id="r1" value="folder-1/" onclick="formaction(this)"/>`
`<label class="check-div" for="r1">Label 1</label>`
`<input type="checkbox" name="rGroup" id="r2" value="folder-2/" onclick="formaction(this)"/>`
`<label class="check-div" for="r2">Label 2</label>`
`<input type="checkbox" name="rGroup" id="r3" value="folder-3/" onclick="formaction(this)"/>`
`<label class="check-div" for="r3">Label 3</label>`
`<button type="submit" class="btn btn-primary btn-lg btn-block">Next</button>`
`</div>`
`</form>`
</code>

Here is the script:

<code>
'$(document).ready(function(){'
$('input[type="checkbox"]').click(function(){
var inputValue = $(this).attr("value");
$("." + inputValue).toggle();
});
});
$('[data-toggle="btns"] .btn').on('click', function(){
var $this = $(this);
$this.parent().find('.active').removeClass('active');
$this.addClass('active');
});
$('.selectme input:checkbox').click(function() {
$('.selectme input:checkbox').not(this).prop('checked', false);
});  
$('.provider-checkboxes input:checkbox').click(function() {
$('.provider-checkboxes input:checkbox').not(this).prop('checked', false);
});       
function formaction(checkbox){
document.getElementById("myForm").action = checkbox.value;;
}
function UncheckAll(){ 
var w = document.getElementsByTagName('input'); 
for(var i = 0; i < w.length; i++){ 
if(w[i].type=='checkbox'){ 
w[i].checked = false; 
}
}
} '
</code>



Aucun commentaire:

Enregistrer un commentaire