First off, I have to say that I might be looking at this incorrectly. Thanks in advance for any guidance.
I'm working with a form that needs to confirm a checkbox prior to submitting. I don't have access to the actual site code, I can only add new JS and CSS with Optimizely.
This is the code on the live site that appears to validate that the checkbox is checked. #toggler is the checkbox.
var agreed = false;
$("#button").click( function()
{
if( !agreed )
{
alert( "You must agree before proceeding." );
return false;
}
_gaq.push(['_trackEvent', 'Form Submit', 'Button clicked']);
$('#button').hide();
window.setTimeout(proceed, 700);
return false;
});
function proceed() {
$( '#proceed' ).submit();
}
$("#toggler").click(function() {
agreed = !agreed;
});
function showButton() {
$('#button').toggle();
return false;
}
So the code is immediately setting agreed as false, correct? Then if #toggler is clicked, changes it to false? Or am I reading that incorrectly?
Now what I am trying to do, is if a certain condition is met, then I need that checkbox to be selected automatically and the terms/conditions hidden because they do not apply. This is the code I tried but does not work. When I check the box with code, I'm given the error message that I need to agree to terms before proceeding. I watched the variable in dev tools and it does not change (if that is even what I should be doing...).
jQuery('input#inputName').validateText(function(result) {
if (result.type.name == 'confirmed'){
$(".terms").fadeOut('slow', function() {
agreed = true;
$('#toggler')[0].checked = true;
});
$( "input#inputName" ).css('background-position', '15px 13px, calc(100% - 11px) -29px');
}
});
Thanks again, guys.
Aucun commentaire:
Enregistrer un commentaire