HighDots Forums  

onSubmit and Internet Explorer = trouble

Javascript JavaScript language (comp.lang.javascript)


Discuss onSubmit and Internet Explorer = trouble in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Mark Livingstone
 
Posts: n/a

Default onSubmit and Internet Explorer = trouble - 06-01-2008 , 01:53 AM






I have a form that uses the following: onSubmit="some_var =
'validated';"

FireFox is OK with that. Internet Explorer isn't. any ideas why?

Thanks.

Reply With Quote
  #2  
Old   
VK
 
Posts: n/a

Default Re: onSubmit and Internet Explorer = trouble - 06-01-2008 , 03:23 AM






On Jun 1, 10:53 am, Mark Livingstone <namematters... (AT) msn (DOT) com> wrote:
Quote:
I have a form that uses the following: onSubmit="some_var =
'validated';"

FireFox is OK with that. Internet Explorer isn't. any ideas why?
This code assigns to global variable some_var string value "validated"
and then submits the form so causing new page load with the Javascript
context being reset: so it doesn't matter what value to what do you
assign before that. I don't know what browser and how could be "OK
with that" - you have to explain then what does it mean OK and most
helpful: what are you trying to achieve overall.



Reply With Quote
  #3  
Old   
Mark Livingstone
 
Posts: n/a

Default Re: onSubmit and Internet Explorer = trouble - 06-01-2008 , 10:41 AM



On Jun 1, 4:23*am, VK <schools_r... (AT) yahoo (DOT) com> wrote:
Quote:
On Jun 1, 10:53 am, Mark Livingstone <namematters... (AT) msn (DOT) com> wrote:

I have a form that uses the following: onSubmit="some_var =
'validated';"

FireFox is OK with that. Internet Explorer isn't. any ideas why?

This code assigns to global variable some_var string value "validated"
and then submits the form so causing new page load with the Javascript
context being reset: so it doesn't matter what value to what do you
assign before that. I don't know what browser and how could be "OK
with that" - you have to explain then what does it mean OK and most
helpful: what are you trying to achieve overall.
I am using jQuery Forms script to bind to the submit action. so, when
the onSubmit fires, the script picks it up, runs a certain function
and prevents the form from being submitted using the regular POST
method -- it does that using jQuery's AJAX post method. page doesn't
refresh and JS context is not reset. So, FF is OK with that syntax and
I can recognize the value of some_var but IE doesn't.


Reply With Quote
  #4  
Old   
Mark Livingstone
 
Posts: n/a

Default Re: onSubmit and Internet Explorer = trouble - 06-01-2008 , 10:48 AM



Forgot to mention... if I create a function that assigns a value to
some_var and then do onSubmit="function();", everything works fine.
It's just that IE doesn't want to recognize onSubmit="some_var =
'value';" or onSubmit="somevar = 1;" syntax.

Reply With Quote
  #5  
Old   
VK
 
Posts: n/a

Default Re: onSubmit and Internet Explorer = trouble - 06-01-2008 , 12:10 PM



On Jun 1, 7:48 pm, Mark Livingstone <namematters... (AT) msn (DOT) com> wrote:
Quote:
Forgot to mention... if I create a function that assigns a value to
some_var and then do onSubmit="function();", everything works fine.
It's just that IE doesn't want to recognize onSubmit="some_var =
'value';" or onSubmit="somevar = 1;" syntax.
If somewhere after page load you do like
document.forms[0].onsubmit = validate;
then it is not important what do you have in the form intrinsic event
listener because it gets overridden. If you have
<form ... onsubmit="some_var='value';">
then this listener is being overriden so never called. This is
consistent across browsers including Firefox, so whatever it is "OK
with that" - it is not what you are describing in this thread. If you
need to assign a value and call form validator and prevent form
submission if not validated then you could use something like:
<form ... onsubmit="return validate(some_var='value')">


Reply With Quote
  #6  
Old   
Evertjan.
 
Posts: n/a

Default Re: onSubmit and Internet Explorer = trouble - 06-01-2008 , 04:51 PM



VK wrote on 01 jun 2008 in comp.lang.javascript:

Quote:
On Jun 1, 10:53 am, Mark Livingstone <namematters... (AT) msn (DOT) com> wrote:
I have a form that uses the following: onSubmit="some_var =
'validated';"

FireFox is OK with that. Internet Explorer isn't. any ideas why?

This code assigns to global variable some_var string value "validated"
and then submits the form so causing new page load with the Javascript
context being reset: so it doesn't matter what value to what do you
assign before that.
This is not always true, VK, try this:

<form onSubmit="some_var = 'validated';" target='_blank' ...

And could be usefully used like this:

==========================================
<form onSubmit="return submitOnlyOnce()" target='_blank' ...

<script type='text/javascript'>
var submitted = false;
function submitOnlyOnce() {
if (submitted) return false;
return submitted = true;
};
</script>
==========================================


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)


Reply With Quote
  #7  
Old   
VK
 
Posts: n/a

Default Re: onSubmit and Internet Explorer = trouble - 06-01-2008 , 05:17 PM



On Jun 2, 1:51 am, "Evertjan." <exjxw.hannivo... (AT) interxnl (DOT) net> wrote:
Quote:
VK wrote on 01 jun 2008 in comp.lang.javascript:

On Jun 1, 10:53 am, Mark Livingstone <namematters... (AT) msn (DOT) com> wrote:
I have a form that uses the following: onSubmit="some_var =
'validated';"

FireFox is OK with that. Internet Explorer isn't. any ideas why?

This code assigns to global variable some_var string value "validated"
and then submits the form so causing new page load with the Javascript
context being reset: so it doesn't matter what value to what do you
assign before that.

This is not always true, VK, try this:

form onSubmit="some_var = 'validated';" target='_blank' ...

And could be usefully used like this:

==========================================
form onSubmit="return submitOnlyOnce()" target='_blank' ...

script type='text/javascript'
var submitted = false;
function submitOnlyOnce() {
if (submitted) return false;
return submitted = true;};

/script
==========================================
You missed the point: of course the intrinsic event handler can be
most useful. I explained that one cannot have two unrelated blocks in
both DOM interface handler and in intrinsic handler: one will be
ignored, namely the intrinsic one.

Doesn't work:

....
document.forms[0].onsubmit = validate;
....
<form ... onsubmit="some_var='value';/* will be ignored */">


Workaround 1:

document.forms[0].onsubmit = function() {
some_var='value';
return validate(this);
}

Workaround 2:

<form ... onsubmit="some_var='value'; return validate(this);">

If some_var is indeed some additional "submission allowed" flag then
it could be even:

<form ... onsubmit="return some_var : validate(this);">

There is a number of other options but nothing of what OP was trying
to do: it is simply not supported.



Reply With Quote
  #8  
Old   
VK
 
Posts: n/a

Default Re: onSubmit and Internet Explorer = trouble - 06-01-2008 , 05:58 PM



On Jun 2, 2:17 am, VK <schools_r... (AT) yahoo (DOT) com> wrote:
Quote:
If some_var is indeed some additional "submission allowed" flag then
it could be even:

form ... onsubmit="return some_var : validate(this);"
A rush of typing, sorry, of course:

<form ... onsubmit="return some_var ? true : validate(this);">
or
<form ... onsubmit="return some_var ? false : validate(this);">

depending on some_var being allowing or blocking flag.


Reply With Quote
  #9  
Old   
Thomas 'PointedEars' Lahn
 
Posts: n/a

Default Re: onSubmit and Internet Explorer = trouble - 06-01-2008 , 06:12 PM



VK wrote:
Quote:
On Jun 2, 2:17 am, VK <schools_r... (AT) yahoo (DOT) com> wrote:
If some_var is indeed some additional "submission allowed" flag then
it could be even:

form ... onsubmit="return some_var : validate(this);"

A rush of typing, sorry, of course:

form ... onsubmit="return some_var ? true : validate(this);"
or
form ... onsubmit="return some_var ? false : validate(this);"

depending on some_var being allowing or blocking flag.
A more reasonable and more efficient approach would be

<form ... onsubmit="return !!some_var || validate(this);">
or
<form ... onsubmit="return !some_var && validate(this);">

or using some_var in a gauntlet within validate().


PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.