By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,500 Members | 2,766 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,500 IT Pros & Developers. It's quick & easy.

onSubmit and Internet Explorer = trouble

P: n/a
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.
Jun 1 '08 #1
Share this Question
Share on Google+
8 Replies


P: n/a
VK
On Jun 1, 10:53 am, Mark Livingstone <namematters...@msn.comwrote:
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.

Jun 1 '08 #2

P: n/a
On Jun 1, 4:23*am, VK <schools_r...@yahoo.comwrote:
On Jun 1, 10:53 am, Mark Livingstone <namematters...@msn.comwrote:
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.
Jun 1 '08 #3

P: n/a
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.
Jun 1 '08 #4

P: n/a
VK
On Jun 1, 7:48 pm, Mark Livingstone <namematters...@msn.comwrote:
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')">
Jun 1 '08 #5

P: n/a
VK wrote on 01 jun 2008 in comp.lang.javascript:
On Jun 1, 10:53 am, Mark Livingstone <namematters...@msn.comwrote:
>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)
Jun 1 '08 #6

P: n/a
VK
On Jun 2, 1:51 am, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:
VK wrote on 01 jun 2008 in comp.lang.javascript:
On Jun 1, 10:53 am, Mark Livingstone <namematters...@msn.comwrote:
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.

Jun 1 '08 #7

P: n/a
VK
On Jun 2, 2:17 am, VK <schools_r...@yahoo.comwrote:
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.
Jun 1 '08 #8

P: n/a
VK wrote:
On Jun 2, 2:17 am, VK <schools_r...@yahoo.comwrote:
>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
Jun 1 '08 #9

This discussion thread is closed

Replies have been disabled for this discussion.