Go Back   Rhinocerus > Newsgroup > Newsgroup comp.lang.java.* > Newsgroup comp.lang.javascript

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 12-21-2006, 07:34 PM
Victor
Guest
 
Posts: n/a
Default 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.photoUpload.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

Reply With Quote
Alt Today
Advertising
 
and become member of Rhinocerus
Standard Sponsored Links

  #2 (permalink)  
Old 12-21-2006, 09:09 PM
Matt Kruse
Guest
 
Posts: n/a
Default Re: Form submit per javascript

Victor wrote:
> // document.forms['photoUpload'].submit();
> document.photoUpload.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


Reply With Quote
  #3 (permalink)  
Old 12-21-2006, 10:01 PM
Victor
Guest
 
Posts: n/a
Default Re: Form submit per javascript


Matt Kruse schrieb:

> Victor wrote:
> > // document.forms['photoUpload'].submit();
> > document.photoUpload.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='multipart/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

Reply With Quote
  #4 (permalink)  
Old 12-22-2006, 01:25 AM
Malkavian
Guest
 
Posts: n/a
Default Re: Form submit per javascript


"Victor" <big.boss@chefmail.de> wrote in message
news:1166733276.670791.276890@f1g2000cwa.googlegro ups.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.photoUpload.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.forms['photoUpload'].elements['photo_1'].value" in
the alert but "document.photoUpload"
when you call the submit function? perhaps if you had "document.photoUpload"
in the alert too or
document.forms['photoUpload'].elements['photo_1'].submit, you may get a
different result.

HTH

>



Reply With Quote
  #5 (permalink)  
Old 12-22-2006, 03:49 AM
Matt Kruse
Guest
 
Posts: n/a
Default Re: Form submit per javascript

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='multipart/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


Reply With Quote
  #6 (permalink)  
Old 12-25-2006, 08:25 PM
Victor
Guest
 
Posts: n/a
Default Re: Form submit per javascript

> Why do you have "document.forms['photoUpload'].elements['photo_1'].value" in
> the alert but "document.photoUpload" when you call the submit function? if you
> had perhaps "document.photoUpload" 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.photoUpload.submit()' without any different
result...

Victor

Reply With Quote
  #7 (permalink)  
Old 12-26-2006, 11:08 AM
Bart Van der Donck
Guest
 
Posts: n/a
Default Re: Form submit per javascript

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.photoUpload.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.photoUpload.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.photoUpload is empty or no object".
FF says "document.photoUpload 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="photoUpload"
enctype="multipart/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

Reply With Quote
  #8 (permalink)  
Old 12-26-2006, 11:10 AM
Bart Van der Donck
Guest
 
Posts: n/a
Default Re: Form submit per javascript

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='multipart/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="multipart/form-data"

and not

encode='multipart/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

Reply With Quote
  #9 (permalink)  
Old 12-26-2006, 11:21 AM
Bart Van der Donck
Guest
 
Posts: n/a
Default Re: Form submit per javascript

Malkavian wrote:

> "Victor" <big.boss@chefmail.de> wrote in message
>
>> alert (document.forms['photoUpload'].elements['photo_1'].value);
>> // document.forms['photoUpload'].submit();
>> document.photoUpload.submit();

>
> Why do you have "document.forms['photoUpload'].elements['photo_1'].value" in
> the alert but "document.photoUpload" when you call the submit function?
> perhaps if you had "document.photoUpload" 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.photoUpload.submit()
if one uses id="photoUpload" inside the <form>-tag. In my experience
I prefer name="photoUpload" . Maybe that's just a habit.

--
Bart

Reply With Quote
  #10 (permalink)  
Old 12-26-2006, 12:25 PM
Malkavian
Guest
 
Posts: n/a
Default Re: Form submit per javascript


"Victor" <big.boss@chefmail.de> wrote in message
news:1167081938.679715.90860@79g2000cws.googlegrou ps.com...
>> Why do you have "document.forms['photoUpload'].elements['photo_1'].value"
>> in
>> the alert but "document.photoUpload" when you call the submit function?
>> if you
>> had perhaps "document.photoUpload" 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.photoUpload.submit()' without any different
> result...
>
> Victor
>

I wasn't being picky. It's just that mixing name conventions causes a lot
of headaches.


Reply With Quote
  #11 (permalink)  
Old 12-26-2006, 12:27 PM
Malkavian
Guest
 
Posts: n/a
Default Re: Form submit per javascript


"Bart Van der Donck" <bart@nijlen.com> wrote in message
news:1167135705.767765.260820@48g2000cwx.googlegro ups.com...
> Malkavian wrote:
>
>> "Victor" <big.boss@chefmail.de> wrote in message
>>
>>> alert (document.forms['photoUpload'].elements['photo_1'].value);
>>> // document.forms['photoUpload'].submit();
>>> document.photoUpload.submit();

>>
>> Why do you have "document.forms['photoUpload'].elements['photo_1'].value"
>> in
>> the alert but "document.photoUpload" when you call the submit function?
>> perhaps if you had "document.photoUpload" 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()


Yes, I did. My bad. Thanks for pointing that out.

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


I do too but min is from old habit. I don't think that older
mozilla/netscape browsers recognise the ID tag but i could be wrong..

>
> --
> Bart
>



Reply With Quote
  #12 (permalink)  
Old 12-26-2006, 08:00 PM
Victor
Guest
 
Posts: n/a
Default Re: Form submit per javascript

Somehow until now nobody has commented the fact that my code works
perfectly in the FireFox. The problem occurs only in the MSIE 6 (I did
not test it with other IE versions).

Any ideas to this point ?

Victor

Reply With Quote
  #13 (permalink)  
Old 12-26-2006, 08:07 PM
Matt Kruse
Guest
 
Posts: n/a
Default Re: Form submit per javascript

Victor wrote:
> Somehow until now nobody has commented the fact that my code works
> perfectly in the FireFox. The problem occurs only in the MSIE 6 (I did
> not test it with other IE versions).


You still haven't posted your actual code, including HTML. How are we
supposed to help you?

Either:
a) Post a url that demonstrates the problem
or
b) Take your generated HTML, remove everything that is not necessary to show
the problem, and post the result here

I'm fairly certain your problem will be resolved very quickly.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com


Reply With Quote
  #14 (permalink)  
Old 12-26-2006, 08:19 PM
Evertjan.
Guest
 
Posts: n/a
Default Re: Form submit per javascript

Victor wrote on 26 dec 2006 in comp.lang.javascript:

> Somehow until now nobody has commented the fact that my code works
> perfectly in the FireFox. The problem occurs only in the MSIE 6 (I did
> not test it with other IE versions).
>
> Any ideas to this point ?
>


Sure, if you do not quote, how should we know what you are talking about?

On usenet you cannot expect the last posting still or already to be on each
news server.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Reply With Quote
  #15 (permalink)  
Old 12-26-2006, 08:30 PM
VK
Guest
 
Posts: n/a
Default Re: Form submit per javascript


Victor wrote:
> Somehow until now nobody has commented the fact that my code works
> perfectly in the FireFox.


That's possibly because no one has seen your code so far. There were
two lines posted and corrected by respondents.

if you have a form with NAME "photoUpload" (ID is not relevant) and it
has element with NAME "photo_1" (ID is not relevant) then
document.forms['photoUpload'].elements['photo_1'].value
will give you photo_1 value (or allowed part of value if type="file")
document.forms['photoUpload'].submit()
will submit this form (unless you managed to create a control in your
form named "submit")

That works for all ever existed browsers since Netscape 2.0 If anything
fails to work then you have much more serious problems then two lines
of code. Without seeing the whole page by URL any further guessing is
rather futile.

Reply With Quote
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Command line macro to submit SAS code Jim Groeneveld Newsgroup comp.soft-sys.sas 0 04-19-2006 08:31 AM
Re: Command line macro to submit SAS code toby dunn Newsgroup comp.soft-sys.sas 0 04-19-2006 02:22 AM
Re: weblog to normal form Sigurd Hermansen Newsgroup comp.soft-sys.sas 0 04-12-2006 09:13 PM
Re: SQL, reduced normal form and dummy variables Sigurd Hermansen Newsgroup comp.soft-sys.sas 0 05-09-2005 10:07 PM
How to create a survey form using SAS ODS - PDF or RTF Kassa2 Bellew Newsgroup comp.soft-sys.sas 0 12-08-2004 11:36 AM



All times are GMT. The time now is 11:49 AM.


Copyright ©2009

LinkBacks Enabled by vBSEO 3.3.0 RC2 © 2009, Crawlability, Inc.