473,386 Members | 1,810 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,386 software developers and data experts.

onSubmit and Internet Explorer = trouble

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
8 6816
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jesper Hermansen | last post by:
Hi! I'm making a system that will generate Winamp-playlists. To make it easy for the user to add a file to the list, I'm using <input type="file">. The problem with this is that I only get...
3
by: maxhitchcock | last post by:
Hi, I made a lots tables in Dreamweaver to put my images in it then I made a menu in Javascript. I'm pretty sure there's no error in my size of cells and they are all valign="top". In Internet...
2
by: Howard Jess | last post by:
CLJ -- I've searched the newsgroup and FAQ for info on insertRow(), but didn't see this reported. It seems that Internet Explorer doesn't respond correctly to either insertRow() or...
0
by: prs(tm) | last post by:
I want to show a custom window above the HTML display much like the Info bar in XP SP2. Within IE, the Internet Explorer Server window is a child of a Shell Doc Object View; I've subclassed the...
3
by: VK | last post by:
Internet Explorer 7 beta 2 preview CNET Editor review: <http://reviews.cnet.com/Internet_Explorer_7_for_XP_SP2_Beta_2/4505-3514_7-31454661-2.html?tag=nl.e415> Summary (my personal review...
3
by: bharath.0523 | last post by:
hi, I have developed a multithreaded MFC activeX control, which i host on the Internet Explorer. when i click on the close button of the Internet Explorer i.e., when the user decides to end the...
8
by: Mark Livingstone | last post by:
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.
3
by: RamNivas | last post by:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1- transitional.dtd"> <html> <head> <title>Login</title> <style type="text/css"> h1 {...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.