469,269 Members | 1,006 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,269 developers. It's quick & easy.

Help! Submitting to FormMail through JavaScript Submit

Hi all:

I'm having a nasty time with a particularly difficult piece of code
and was hoping someone might be able to help me. I have a FormMail
form that originally worked perfectly.

Then, I had to add a JavaScript function to the Submit button to make
a server function run when the form was submitted. Unfortunately,
this JavaScript wouldn't run when the button was designated as a
Submit, so I changed the button and placed a JavaScript submit into my
JavaScript function. Great! The JavaScript worked
perfectly...BUT...that broke my original FormMail submit, so now I'm
not getting e-mails anymore!

Here's the JavaScript function:

function autoURL (realname) {
Builder Pre-test &pname=" + realname;

....and here's the Submit button's code:

<input type="button" value="Submit" id="feedback" name="Submit"

Can anyone help me with this? I'm about to tear my hair out over it!
Jul 23 '05 #1
2 4678
"Margaret Werdermann" coded
Here's the JavaScript function:

function autoURL (realname) {
on.nsf/MarkPreComplete?Openagent&test=Base Builder Pre-test &pname=" + realname;
You 're giving two contradicting commands here. The submit() loads whatever
url is specified as the form's action, after sending the form data to the
server. location.href just loads a different page. Can't go to two places at
the same time.
...and here's the Submit button's code:

<input type="button" value="Submit" id="feedback" name="Submit"

If you specify both an id and a name for a form element, according to
standards they should be identical.
If this replaces the <input type="submit">, you end up with a form with no
submit button. That in itself may cause attempts to submit() to fail. I
suspect this is why the first line did not execute in your above function;
if the form had submitted, the second would not have run and you would not
have ended up at specified url.

The onclick event handler can be set on that button (sometimes even if it is
hidden) to add script to that specific event: clicking the submit-button.
But browsers generally allow users to submit forms by hitting the return key
in an ordinary text-input. In code, we need to tackle the onsubmit event of
the form element instead.

Like so:
<form onsubmit=" return doSomething(this); ">
<input type="text" value="type here and hit enter">
<input type="submit" style="display:none;">

This function should return either true or false (or anything that may be
interpreted as such - anything). If this function were to return false, the
form would not be submitted, the page would remain. With a return value of
true the data are sent to the server, which results in a new page being

Like so:
function doSomething(){
return confirm('Do you want to submit the form?');

Or so:
function doSomething( el ){
var x=el.elements[0].value.length;
if ( x < 3 ) {
alert('At least three characters, please..');
return false;
} else {
return true;

The function can do all sorts of things before returning its value (if it
doesn't return anything, this is interpreted as true) including spawning and
closing windows. This appears to be a worst-case solution looking at what
you were trying to do. (The real problem is often not javascript but
back-end related.)
It should be clear that is makes no sense (probably results in awful
crashes) to call form.submit() in this function because it only runs when
this event is already happening. The submit() method would be useful for
initiating this process by any other means than those provided by the form
To be of more specific help, some more code would help identify the idea,
what you are actually trying to achieve, and the problem.


Jul 23 '05 #2
Thanks so much Ivo! We did finally get it to work. You were right on
with your explanation. Here's what we did to make it work:

First, we changed the JavaScript function completely to run our
automatic script from a new window, like this:

function autoURL (realname) {
var urladd="URL to run the automatic script" + realname;
var urltit="suitable title bar text";
var urlopt="width=600, height=600, toolbar=yes, resizable=yes,
scrollbars=yes, status=yes";
return true;

Then, we placed the call to the JavaScript function into an onSubmit in
the form, like this:

<form action="URL to our cgi bin" method="POST" name="MailTest"
id="MailTest" onsubmit="return

Then we could go back to just a regular HTML Submit button, like this:

<input type="submit" name="Submit" value="Submit">

That did it! The automatic script ran and the form was submitted
successfully through FormMail. I hope this helps someone else.

Thanks again,


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Tom | last post: by
6 posts views Thread by wukexin | last post: by
3 posts views Thread by Colin J. Williams | last post: by
7 posts views Thread by Corepaul | last post: by
5 posts views Thread by Steve | last post: by
8 posts views Thread by Mark | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.