473,406 Members | 2,281 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,406 software developers and data experts.

Problem submitting form via JS

I have code that calls document.myFormName.submit() to submit a form
automatically via JavaScript. This works just fine.

However, if there is a button (or other form field element) on the form
named "submit", this results in a JS error saying that "the object doesn't
support this property or method". I think what is happening in this case is
that document.myFormName.submit() is then trying to call a method on the
form field element named "submit" instead of just submitting the form. As
mentioned earlier, this works if there is no form field element named
"submit" so apparently there is some sort of clash or conflict here.

Now I know what you are thinking - "hey, just don't create a form field
element named "suibmit" on the form or call it something else!".
Unfortunately I cannot control the submitted form itself. My code is sort
of like middleware in that other programmers post their forms into (they
post their forms into me, I intercept it and add somethings, and then use JS
to automatically resubmit the form). As such, I need to be able to submit
the form via JavaScript whether or not there is a field element named
"submit" and avoid this clash/conflict.

How can this be done? I'm thinking that perhaps there is a more formal
naming convention like document.something.something.submit() that would
explictly get to the form's submit method and avoid the possible clash with
a form field element that may be named "submit"? I need this to work with
all modern browsers so if the code is different for doing this in IE windows
vs. Netscape etc please let me know both ways.

Thanks!!

Jul 23 '05 #1
1 1627


Richard Dixson wrote:
I have code that calls document.myFormName.submit() to submit a form
automatically via JavaScript. This works just fine.

However, if there is a button (or other form field element) on the form
named "submit", this results in a JS error saying that "the object doesn't
support this property or method". I think what is happening in this case is
that document.myFormName.submit() is then trying to call a method on the
form field element named "submit" instead of just submitting the form. As
mentioned earlier, this works if there is no form field element named
"submit" so apparently there is some sort of clash or conflict here.


While accessing elements by name is possible with
formElement.elements.elementName
or
formElement.elements['elementName']
there is no way to access the method of the name 'submit' if a form
control overwrites that method.
The only thing you could try is to store the method before it is
overwritten e.g.
<form name="formName" action="whatever.php">
<script type="text/javascript">
var newSubmitName = 'submit' + new Date().getTime();
document.forms.formName[newSubmitName] =
document.forms.formName.submit;
</script>
... inputs follow here ...
and then you use
document.forms.formName[newSubmitName]();
to submit the form. I think that should work but I have never tried
that. Let us know whether that works for you.

Another way to submit a form is to call the click method of a submit
button thus if you know or can ensure there is one e.g.
<input type="submit" name="submitButton">
then you can use
document.forms.formName.elements.submitButton.clic k()
to submit the form with script.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2

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

Similar topics

1
by: Reffo | last post by:
*This message is also posted in alt.php* Hi. This is a part of a form I'm using: <?php if($sentmessage == '3'){ echo "You have already posted 3 times!"; exit(); }else{
3
by: Tong | last post by:
I have a simple .asp page with a text field and submit button. When it runs on a Win 2000 Professional + IE6 client machine, and the .asp page is set "anonymous access" only on IIS, the contents I...
2
by: Greg T | last post by:
Hi, I have a rather long form that I don't want people submitting unless they are absolutely sure they are ready. I figured the easiest way to prevent an accidental form submission by way of...
1
by: fogwolf | last post by:
First a basic outline of what I am trying to do: I want to have a page spawn a pop-up when you click "submit" on its form. On this pop-up page there will be another form. When you click "submit"...
5
by: Don | last post by:
I have a need to submit a form, but don't need the user to click on a button. How do I do this? Is there some way, using JavaScript, to setup a <form> tag to do this? Thanks, Don ----==...
10
by: tasmisr | last post by:
This is an old problem,, but I never had it so bad like this before,, the events are refiring when clicking the Browser refresh button. In the Submit button in my webform, I capture the server side...
5
by: Steve | last post by:
Hi, I currently have a problem passing a variable value from one page to another. Once a form submit button is pressed java pops up a window and displays some information. The problem being is...
7
by: mohammed.naghman | last post by:
Hi, I have 2 submit buttons in a jsp page. One of them takes me to page2.jsp and also passes the values enetered to page2.I have a link in the page2 that does a history.back to come to the...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.