Forum Moderators: open

Message Too Old, No Replies

Call <form ... onsubmit="return check_submit()">

within another js function

         

iProgram

6:28 am on Feb 22, 2005 (gmt 0)

10+ Year Member



Here is my situation:

<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?

orion_rus

2:14 pm on Feb 22, 2005 (gmt 0)

10+ Year Member



it would be better to make two buttons type='submit' with equal name like
<input type='submit' name='submit' value='Submit' />
<input type='submit' name='submit' value='Preview' />
and in a server side check value of like $_POST['submit'] and make needed function in dependency of it value;

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