I have this submit button on my website.
<form name="bbsform" action="<?=$PHP_SELF?>" method="post"
<input type="submit" value="Submit" onclick="this.disabled=true,this.form.submit();" />
</form>
The onClick part disables the submit button immediately after the first click, to prevent possible double submission of the form. And it perfectly works.
And I also have made this javascript function, too. Let's say it's called 'Guidance(bbsform)'.
Briefly, when a user forgot to complete one field in the form, it shows an alert message and focuses to the field. (It work like that some invisible cursor is automatically clicking on the field, so the user can start typing right away.) This function works great too.
They both work great, well at least separately.
But when I combine them like this :
onclick="return Guidance(bbsform);this.disabled=true,this.form.submit();"
Only the Guidance function properly works.
Could you tell me what's wrong with the code?
Thank you for reading. I'm a newbie to this whole programming thing, so please be generous :)
Here is the Guidance function. Sorry none of the solutions worked.. It's really frustrating.
function Guidance(frm){
if(frm.subject.value == ""){
alert("Please complete the title field.");
frm.subject.focus();
return false; }
try{ content.outputBodyHTML(); } catch(e){ }
if(frm.content.value == ""){
alert("Please complete the message field.");
frm.content.focus(); return false; }
return Guidance(bbsform);andthis.disabled=true,this.form.submit();are two statements, but thereturnstatements always terminates the current function, that's why the assignment and the other function call are never executed.