473,671 Members | 2,250 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Form submit per javascript

Hi everybody!

I am experiencing a strange - at least for me - phenomen.
I have a func containing the following code :

alert (document.forms['photoUpload'].elements['photo_1'].value);

// document.forms['photoUpload'].submit();
document.photoU pload.submit();

This code works perfectly in the FF, but not in the IE. The alert
outputs the proper value of the element photo_1 and then the line with
submit() produces [objectError] - checked by means of try-catch and
displayed with alert(e) in the catch-block. This concerns the both
lines with the submit().

What could be a cause for this problem?

Victor

Dec 21 '06 #1
22 2645
Victor wrote:
// document.forms['photoUpload'].submit();
document.photoU pload.submit();
The first form is preferred. Why is it commented out?
This code works perfectly in the FF, but not in the IE. The alert
outputs the proper value of the element photo_1 and then the line with
submit() produces [objectError]
First thing I would check is to make sure you don't have an input named
"submit".

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Dec 21 '06 #2

Matt Kruse schrieb:
Victor wrote:
// document.forms['photoUpload'].submit();
document.photoU pload.submit();

The first form is preferred. Why is it commented out?
Neither of the both wants to work here. The outcommented line has been
simply copied from the running code, never mind about it.
This code works perfectly in the FF, but not in the IE. The alert
outputs the proper value of the element photo_1 and then the line with
submit() produces [objectError]

First thing I would check is to make sure you don't have an input named
"submit".
No, I don't !

However, I have discovered that the problem gets eliminated when I try
to upload a different form rather than the 'photoUpload', which has
(!!!!) encode='multipa rt/form-data'. Can this be the real source of the
problem? If yes, then how to fix it? And why does it work in the FF?

Regards
Victor

Dec 21 '06 #3

"Victor" <bi******@chefm ail.dewrote in message
news:11******** **************@ f1g2000cwa.goog legroups.com...
Hi everybody!

I am experiencing a strange - at least for me - phenomen.
I have a func containing the following code :

alert (document.forms['photoUpload'].elements['photo_1'].value);

// document.forms['photoUpload'].submit();
document.photoU pload.submit();

This code works perfectly in the FF, but not in the IE. The alert
outputs the proper value of the element photo_1 and then the line with
submit() produces [objectError] - checked by means of try-catch and
displayed with alert(e) in the catch-block. This concerns the both
lines with the submit().

What could be a cause for this problem?

Victor
Why do you have "document.f orms['photoUpload'].elements['photo_1'].value" in
the alert but "document.photo Upload"
when you call the submit function? perhaps if you had "document.photo Upload"
in the alert too or
document.forms['photoUpload'].elements['photo_1'].submit, you may get a
different result.

HTH
>

Dec 22 '06 #4
Victor wrote:
However, I have discovered that the problem gets eliminated when I try
to upload a different form rather than the 'photoUpload', which has
(!!!!) encode='multipa rt/form-data'. Can this be the real source of
the problem?
I don't know.

I would take these steps:
1. Try submitting the form manually, without javascript
2. Try taking elements out of the form until it works, then figure out which
piece made it break
3. Have a non-script fall-back, so even in the event of errors like this,
the form would still get submitted

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Dec 22 '06 #5
Why do you have "document.f orms['photoUpload'].elements['photo_1'].value" in
the alert but "document.photo Upload" when you call the submit function? if you
had perhaps "document.photo Upload" in the alert too or
document.forms['photoUpload'].elements['photo_1'].submit, you may get a
different result.
I did try it with the 'document.forms['photoUpload']... ' in the alert
and with the 'document.photo Upload.submit() ' without any different
result...

Victor

Dec 25 '06 #6
Victor wrote:
I am experiencing a strange - at least for me - phenomen.
I have a func containing the following code :

alert (document.forms['photoUpload'].elements['photo_1'].value);

// document.forms['photoUpload'].submit();
document.photoU pload.submit();

This code works perfectly in the FF, but not in the IE. The alert
outputs the proper value of the element photo_1 and then the line with
submit() produces [objectError] - checked by means of try-catch and
displayed with alert(e) in the catch-block. This concerns the both
lines with the submit().

What could be a cause for this problem?
I might have reconstructed your problem:

<script type="text/javascript">
function sV() {
alert (document.forms['photoUpload'].elements['photo_1'].value)
document.photoU pload.submit()
}
</script>
<form method="post" action="script. php" id="photoUpload ">
<input type="file" name="photo_1">
<input type="button" value="click me" onClick="sV();" >
</form>

IE says "document.photo Upload is empty or no object".
FF says "document.photo Upload has no properties".

There are a number of things that are not good in this kind of code.

Better:

<form method="post" action="script. php" name="photoUplo ad"
enctype="multip art/form-data" onSubmit="
alert(document. forms['photoUpload'].elements['photo_1'].value)">
<input type="file" name="photo_1">
<input type="submit" value="click me">
</form>

Is the alert only meant for debugging purposes ? Then the
onSubmit-handler can be left out.

--
Bart

Dec 26 '06 #7
Victor wrote:
[...]
However, I have discovered that the problem gets eliminated when I try
to upload a different form rather than the 'photoUpload', which has
(!!!!) encode='multipa rt/form-data'. Can this be the real source of the
problem? If yes, then how to fix it? And why does it work in the FF?
The right syntax is

enctype="multip art/form-data"

and not

encode='multipa rt/form-data'

AFAIK, this should normally not affect the javascript. But it's
necessary to add it for other reasons (to be technical, so that your
parsing program - e.g. PHP, ASP... - knows that the POST-request
consists of multiple parts divided by a defined separator).

--
Bart

Dec 26 '06 #8
Malkavian wrote:
"Victor" <bi******@chefm ail.dewrote in message
>alert (document.forms['photoUpload'].elements['photo_1'].value);
// document.forms['photoUpload'].submit();
document.photo Upload.submit() ;

Why do you have "document.f orms['photoUpload'].elements['photo_1'].value" in
the alert but "document.photo Upload" when you call the submit function?
perhaps if you had "document.photo Upload" in the alert too or
document.forms.['photoUpload'].elements['photo_1'].submit, you may get a
different result.
You can't do

document.forms['photoUpload'].elements['photo_1'].submit()

Perhaps you meant

document.forms['photoUpload'].submit()

The latter is a difference compared to document.photoU pload.submit()
if one uses id="photoUpload " inside the <form>-tag. In my experience
I prefer name="photoUplo ad" . Maybe that's just a habit.

--
Bart

Dec 26 '06 #9

"Victor" <bi******@chefm ail.dewrote in message
news:11******** *************@7 9g2000cws.googl egroups.com...
>Why do you have "document.f orms['photoUpload'].elements['photo_1'].value"
in
the alert but "document.photo Upload" when you call the submit function?
if you
had perhaps "document.photo Upload" in the alert too or
document.for ms['photoUpload'].elements['photo_1'].submit, you may get a
different result.
I did try it with the 'document.forms['photoUpload']... ' in the alert
and with the 'document.photo Upload.submit() ' without any different
result...

Victor
I wasn't being picky. It's just that mixing name conventions causes a lot
of headaches.
Dec 26 '06 #10

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

Similar topics

4
7787
by: Sarah | last post by:
Hi all. I have a form, and several text and image links on it that should submit the form with different actions. I prepared a simple page with just the code that's not working. PROBLEM: The form won't submit if the link is clicked, but will submit if the SUBMIT button is clicked. I need to call a function to change the form's action according to user's input before it is submitted.
1
10502
by: jrefactors | last post by:
When the user type something in text box, and press enter, it will submit the form data to test2.jsp, even without pressing submit form button. This is not what I want, I want to submit the form only when the user press the submit button. Any workarounds? Please advise. thanks!! <script type="text/javascript">
4
9295
by: Stuart Perryman | last post by:
Hi, I have the following code which works just fine in IE6 but not in Firefox. It is an extract of several table rows each with an individual form. It is generated by php. <form action="MaintNotification.php?ReqID=5" method="post" name="frm5"> <tr align="left" bgcolor="#dddddd" class="text" onClick="submit()"
11
2995
by: Brian D | last post by:
I have been searching for a while to find an answer to this and I must be searching on the wrong keywords. Below is a snippet of my form. There are other form items on it, but I need to submit a different value based on the image that is clicked. Lets say the name is "image" and the value is . How do I submit this with javascript? <form name="form1" method="post" action="launch.asp">
0
1881
by: 42 | last post by:
I implemented a simple class inherited from Page to create a page template. It simply wraps some trivial html around the inherited page, and puts the inherited page into a form. The problem I have run into is that the emitted html at the end of the process is slightly different and doesn't work. Please don't be put off by all the source code. All the guts are in this first base class, and it doesn't do much. The rest is trivial...
5
17696
by: Navillus | last post by:
Hey gang, I have a login form that is empty by default, but can be filled with values from a previous form: <input type=text maxlength="40" size="40" name="user" value="`usr`"> <input type=password maxlength="8" name="password" value="`pss`"> where usr and pss are sent from the previous form.
9
6760
by: Veerle | last post by:
Hi, When you use multiple asp:Buttons on one Form, then asp.net generates html submit buttons for all of them. When you put your cursor in one of the textfields of the form, the default submit button is the first submit button of the form. So if you press enter, then the form is submitted as if you pressed the first submit button of the form. But sometimes, you want the default button to be the second or third submit button of your...
4
5504
by: j1dopeman | last post by:
Hi, I'd like to use a button to save and then submit a form. I can set the onlick of the button to mahButton_click or submit, but I can't figure out how to do both. It looks like c# can't call a form's submit. I've found how to post programatically, but I need to use the form's target attribute so that the response goes into another frame, and I can't figure out how to do that programatically.
11
5290
by: V S Rawat | last post by:
using Javascript, I am opening a web-based url in a popup window. MyWin1=Window.Open(url, "mywindow") There is a form (form1) in the url in that popup window, I need to submit that form. How do I submit that form1 from the javascript from my current window? Thanks.
13
3591
by: Andrew Falanga | last post by:
HI, Just a warning, I'm a javascript neophyte. I'm writing a function to validate the contents of a form on a web page I'm developing. Since I'm a neophyte, this function is quite simple at this time (in fact, I don't even know if it totally works, I'm still debugging). However, the first problem is that when an error is encountered, I get my alert box, I press ok and then the form is submitted and the new data is entered into the...
0
8476
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8393
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8598
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8670
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7437
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5696
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4407
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2051
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1809
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.