Forum Moderators: open
<script language="javascript">
function check(form) {
var obj,msg;
msg = '';
var requireds = new Array('cboCategory','txtsubject');
for (i=0;i<requireds.length;i++) {
obj=eval('form.'+requireds[i]);
if ((obj.type=='select-one') && (obj.selectedIndex==0)) {
msg = 'Please select your '+ requireds[i];
}
else if (obj.value == '') {
msg = 'Please enter your ' + requireds[i];
}
if (msg!='') { break; }
}
if (msg!= '') { alert(msg); }
else { form.submit(); }
}
</script>
<form name="form1" method="POST" action="submit_blog.php">
more form fields here i didnt include them all
<textarea name="txtBody" rows="20" cols="70"></textarea>
<input type="hidden" name="addblog" value="yes">
<input type="submit" name="addblog" value=" Post " onclick="check(this.form);">
<form name="form1" method="POST" action="submit_blog.php">
more form fields here i didnt include them all
<textarea name="txtBody" rows="20" cols="70"></textarea>
<input type="hidden" name="addblog" value="yes">
<input type="submit" name="addblog" value=" Post " onclick="return check(this.form);">
Also consider taking onclick off input submit and add onsubmit="return check(this);" to form element