It's up to each one preferences.
There is not just 1 way of doing something.
I personally prefer to use a simple button, that will call a javascript fnuction that will do the submit, rather than a submit button that I will stop the effect later.
Simply the logic seems wrong to stop an action that have started.
I prefer to check it before.
Look at this bit of javascript
:
Code:
<script type="text/javascript">
function submitForm(){
var inputError=true;
//For a text input
var val1=document.getElementById('field1').value;
//For a drop down select
var sel1=document.getElementById('select1').options[document.getElementById('select1').selectedIndex].value
//For a radio button
for(i=0;i<document.getElementById('radio1').length;i++){
if(document.getElementById('radio1').checked){
var radio1=document.getElementById('radio1').value;
}
}
//Now, do the checks you need with your values...
...
if(1 == 1){
//Just for the demo, we validate the datas
inputError=false;
}
//And if there are no errors, simply submit the form
if(inputError==false){
document.getElementById('myForm').submit();
}
}
</script>
This function goes with this form:
Code:
<form name="myForm" id="myForm" method="post" action="http://www.whatever.com"/>
<input type="text" name="field1" id="field1"/><br/>
<select name="select1" id="select1">
<option value="1">First</option>
<option value="2">Second</option>
<option value="3">Third</option>
</select><br/>
<input type="radio" name="radio1" id="radio1" value="one"/><br/>
<input type="radio" name="radio1" id="radio1" value="two"/><br/>
<input type="radio" name="radio1" id="radio1" value="three"/><br/>
<input type="button" value="click me, you fool" onclick="javascript:submitForm();"/>
</form>
And the combination of those two will make the form validated and submitted upon the click on the button, via the calling of the javascript function.