I have a form which enables the submit button only when a checkbox is selected. The problem is that people without JavaScript will never be able to enable the submit button. What is the best solution to this problem?
<script src="http://www.lenticularpromo.com/v/vspfiles/js/jquery-1.6.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
$('#accept-box').click(function(){
$('#submitter').attr('disabled',!this.checked);
});
$('#myform').submit(function(){
return $('#accept-box').attr('checked');
});
});
</script>
<form id="myform" class="accept" action="http://dropbox.yousendit.com/KefengXu11610470" method="GET">
<label>I promise to include all required information along with my artwork submission</label>
<input id="accept-box" n开发者_运维问答ame="accept" type="checkbox" value="0">
<br>
<input id="submitter" class="submit" type="submit" name="submit" value="Continue to artwork upload" disabled="disabled">
</form>
In my opinion, the best option would be to keep the submit button enabled in the HTML and disable it using the JavaScript. And then validate on the server-side that the checkbox has been checked (you should always validate server-side even if you do client-side, JavaScript can be disabled or bypassed).
Don't hardcode the disabled
attribute in your markup. Instead, add that attribute via javascript/jquery. That way, if you do not have JS, it is never disabled, but if you do have JS, your logic applies.
You'll want to follow up on the server side, of course, since now you can just disable JS to get past the "checkbox click" button requirement.
the best way is to tell them to enable the JS or check this only on server side.
even google does that.
You can use <noscript> tags on the page to display a special message for users who do not have javascript enabled. Tell them the site will not perform ideally without js, then do your validation on the server.
精彩评论