I need a checkbox, where you move from one page to another after clicking the box. The checkbox should be required, given that you’ve read the terms and conditions link next to it.
I’m only half sure how to do this, something like this:
<input type="checkbox" value="confirm_prepay_terms" name="confirm_prepay_terms" align="middle" />
with Jquery:
<script type="text/javascript" language="javascript">
$(document).ready(function() {
if ($('form#prepay input:checkbox', 'confirm_prepay_terms').is(':checked') {
return true;
} else {
$('#confirm_terms_hint').text('Please try again - you need to check the box to move on');
$('#confirm_terms_hint').css('font-weight', 'strong');
return false;
}
}
</script>
At the moment though, I can’t view the checkbox at all on the page, so perhaps my HTML is incorrect?
Hope you can help.
Your HTML is fine – is will show a checkbox – but without any text. You could add some using this markup :
In your JavaScript you are missing a closing
):should be
and a
)on the last line :should be
and your selector is incorrect
should be
This uses the multiple attribute selector
and
should be
font-weighthas nostrongvalue (see here) … useboldinsteadin your script you are returning
trueorfalsebut the code is not being called by anything – its executing as soon as the page has completed loading. Have a look at the .submit() method in jQuery if you want to perform form validation. An example would be this :This would prevent the form from being submitted now – as you return
falseto the submit event.Fully working example here