You should not, in general:
- Mix your JavaScript into your HTML markup (you should attach your logic handlers programmatically),
- (ab)use anchor elements for JavaScript only (you should use a button, or put the
onclick handler on the img directly), nor
- place a form's submission handler on the click of a single element (you should instead handle the
onsubmit event of the form).
I don't know the specifics of your situation, but I would do this in your HTML file:
<!-- Put a valid doctype here -->
<html><head>
<script type="text/javascript" src="submit.js"></script>
</head><body>
<form id="myform" ...>
<label>
<input type="checkbox" name="accept" id="accept-box" />
I accept
</label>
<button type="submit" id="submitter" disabled="disabled">
<img src="..." />
</button>
</form>
</body></html>
...and this in your submit.js file:
window.onload = function(){
var accept = document.getElementById('accept-box');
var submit = document.getElementById('submitter');
accept.onclick=function(){
submit.disabled = !accept.checked;
};
document.getElementById('myform').onsubmit = function(){
// Prevent form submission by any means unless
// the accept button is checked.
return accept.checked;
};
};
(Well, actually, I personally would use jQuery for handling the JS side of things :)
$(function(){
$('#accept-box').click(function(){
$('#submitter').attr('disabled',!this.checked);
});
$('#myform').submit(function(){
return $('#accept-box').attr('checked');
});
});
You can use CSS to style away the button surrounding the image, if you like:
#submitter { border:0; padding:0 }