Forum Moderators: open
<form method="post" action="123.php" onsubmit="return check_submit(this);">
...
<input type="hidden" name="action">
<input type="button" name="Submit" value="Submit" onclick="submit_frm(frm, 'submit')">
<input type="button" name="Preview" value="Preview" onclick="submit_frm(frm, 'preview')">
</form>
Related JS code:
function check_submit(frm)
{
alert('test, on submit');
}function submit_frm(frm, act)
{
frm.action=act;
frm.submit();
}
As you see, I have two buttons (<input type="button") which can submit the form to 123.php. 123.php will check the value of var "action" (<input type="hidden" name="action">), which is set by submit_frm function.
The problem is, I also need to check some input data within check_submit function! And, as you've already known, the frm.submit() function of js won't "call back" the function in onsubmit="" attribute. To make the question simple, I can not explain why I don't put codes of check_submit inside submit_frm. My question is, how to notify the form or the document to call onsubmit="return check_submit(this)" after (before?) frm.submit(); executes?
in a form
<form method="post" action="123.php" onsubmit="return check_submit(this);">
in a check_sumbit function you should make return value;
function check_submit(frm)
{
checking variables
if correct : return true;
if not: return false;
}
I think all will be well here)
Good luck to you