473,378 Members | 1,067 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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) {
window.document.forms[0].submit();
window.location.href="http://ceridianet.ceridian.ca/applications/accreditation.nsf/MarkPreComplete?Openagent&test=Base
Builder Pre-test &pname=" + realname;
}

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

<input type="button" value="Submit" id="feedback" name="Submit"
onclick="autoURL(document.forms[0].realname.value);">

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

function autoURL (realname) {
window.document.forms[0].submit();
window.location.href="http://ceridianet.ceridian.ca/applications/accreditati
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"
onclick="autoURL(document.forms[0].realname.value);">


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;">
</form>

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
loaded.

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
itself.
To be of more specific help, some more code would help identify the idea,
what you are actually trying to achieve, and the problem.

HTH
Ivo

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";
window.open(urladd,urltit,urlopt)
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
autoURL(document.forms[0].realname.value)">

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,

Margaret

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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help...
9
by: Tom | last post by:
A question for gui application programmers. . . I 've got some GUI programs, written in Python/wxPython, and I've got a help button and a help menu item. Also, I've got a compiled file made with...
6
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing...
3
by: Colin J. Williams | last post by:
Python advertises some basic service: C:\Python24>python Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> With...
7
by: Corepaul | last post by:
Missing Help Files When I enter "recordset" as the keyword and search the Visual Basic Help index, I get many topics of interest in the resulting list. But there isn't any information available...
5
by: Steve | last post by:
I have written a help file (chm) for a DLL and referenced it using Help.ShowHelp My expectation is that a developer using my DLL would be able to access this help file during his development time...
8
by: Mark | last post by:
I have loaded Visual Studio .net on my home computer and my laptop, but my home computer has an abbreviated help screen not 2% of the help on my laptop. All the settings look the same on both...
10
by: JonathanOrlev | last post by:
Hello everybody, I wrote this comment in another message of mine, but decided to post it again as a standalone message. I think that Microsoft's Office 2003 help system is horrible, probably...
1
by: trunxnirvana007 | last post by:
'UPGRADE_WARNING: Array has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"' 'UPGRADE_WARNING: Couldn't resolve...
0
by: hitencontractor | last post by:
I am working on .NET Version 2003 making an SDI application that calls MS Excel 2003. I added a menu item called "MyApp Help" in the end of the menu bar to show Help-> About. The application...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.