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

window.event.returnValue = false in firefox

(I'm not a programer, I have learned enough php to build my cms, but
that doesn't make me coding guru, so please excuse me if I'm asking
something trivail...)

well, I have one upload form where I want my users to choose category
for their picture. they are alowed to upload more then one picture at
time. and there is a problem. I have to use
<select name="name[$num]">
for my php script, so I have added id to the select tag
<select id="katSelector$num" name="name[$num"]>
so I can test if there is the same number of choosen category as the
number od pictures chossen for upload:
(whole php/javascript function:)

function validateCat()
{
<?
$uvjeti = "";
for ($num=0; $num<$brsl; $num++) {
$element = "$uvjeti(document.iduslike.katSelector$num.val ue == 0)";
if ($num < ($brsl - 1)) {
$uvjeti = "$element || ";
}
else {
$uvjeti = "$element";
}
}
echo"if ($uvjeti) {\n alert( \"just alert message\" );\n
window.event.returnValue = false;\n t}";
?>
}

in a case of 2 photos to upload, above functions create following code
in my page:

<script type="text/javascript">
<!--
function validateCat()
{
if ((document.iduslike.katSelector0.value == 0) ||
(document.iduslike.katSelector1.value == 0)) {
alert( "just alert message" );
window.event.returnValue = false;
}
}
//-->
</script>

and that works in Safari on my Mac, that works in IE on friends PC, but
that doesn't work on Firefox on any platform: I'm getting alert mesage,
but my upload function gets executed.

I have found that FF (and NN) doesn't understud:
window.event.returnValue = false;

It is now second day as I'm trying to find solution, but my knowlage of
js (and other variations) is so limited that I just can't go anmy
further...

please, can anyone help me?
here is whole form for case with just one photo to upload:
(trimed some irelevant lines)
(as seen in browser!)

<form name="iduslike" enctype="multipart/form-data" action=""
method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="153600">
<input name="userfile[0]" type="file">
<input type="text" name="slika_naziv[0]" size="20">
<select id="katSelector0" name="slika_kategorija[0]">
<option value="0">IZABERI KATEGORIJU!</option>
<option value="1">kategorija 1</option>
<option value="2">kategorija 2</option>
<option value="3">kategorija 3</option>
</select>
<input type="submit" value="upload" onClick="validateCat()">
<input type="reset">
</form>

--
Ja NE
http://fotozine.org/?omen=janimir
--
Dec 7 '05 #1
9 17860
Ja NE <hi****@mail.zz> wrote:
function validateCat()
{
if ((document.iduslike.katSelector0.value == 0) ||
(document.iduslike.katSelector1.value == 0)) {
alert( "just alert message" ); try { window.event.returnValue = false; } catch( dummy ) {}
return false; // Tell non-IE to ignore event }
}


I don't claim that's the most elegant solution, but it's effective.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Dec 7 '05 #2
On 07/12/2005 15:03, Ja NE wrote:
I have to use
<select name="name[$num]">
for my php script, so I have added id to the select tag
<select id="katSelector$num" name="name[$num"]>
There's no need to introduce an id attribute. Just use square bracket
notation:

formObject.elements['name[' + num + ']']

The value of the variable, num, can either be constant (zero to match
'name[0]'), or varied in a loop.

[snip]
<script type="text/javascript">
<!--
Omit the SGML comment. It's unnecessary.
function validateCat()
{
if ((document.iduslike.katSelector0.value == 0) ||
(document.iduslike.katSelector1.value == 0)) {
alert( "just alert message" );
window.event.returnValue = false;
}
}


Expanding on my suggestion above, it would be better to generate code
that resembles:

function validateCat(form) {
for(var i = 0; i < XX; ++i) {
var category = form.elements['name[' + i + ']'];

if('0' == category.options[category.selectedIndex].value) {
alert('...');
return false;
}
}
return true;
}

where XX is the number of SELECT elements, and seems to be $brsl in your
PHP code.

There are a few changes in that code, but two are more significant than
the others.

1. The validateCat function has an argument, form. This is a
reference to the form being validated. This value can either
be supplied from the onsubmit handler:

<form ... onsubmit="return validateCat(this);">

or an onclick handler on a submit button, but the former is
better, in my opinion.
2. Rather than assigning a value to the returnValue property of
an event object, the cod above will simply return that
value.

Your code will fail in Fx and others for two reasons. The
first is that most browsers do not have a global event
object, so window.event will evaluate to undefined.
Secondly, the returnValue property is a proprietary feature.
In other browsers returning a value from an event listener
is equivalent, and is supported by IE, too.

Hope that helps,
Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Dec 7 '05 #3
Christopher Benson-Manica wrote:
Ja NE <hi****@mail.zz> wrote:
function validateCat()
{
if ((document.iduslike.katSelector0.value == 0) ||
(document.iduslike.katSelector1.value == 0)) {
alert( "just alert message" );

try {
window.event.returnValue = false;

} catch( dummy ) {}
return false; // Tell non-IE to ignore event


So IE is not IE ...
}
}


I don't claim that's the most elegant solution, but it's effective.


Effective to break where Exception handling is not supported? Yes.
Effective to submit the form anyway? Yes.
PointedEars
Dec 8 '05 #4
Thomas 'PointedEars' Lahn <Po*********@web.de> wrote:
Effective to break where Exception handling is not supported? Yes.
What UA with any currency doesn't support exception handling?
Effective to submit the form anyway? Yes.


How so?

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Dec 9 '05 #5
Christopher Benson-Manica wrote:
Thomas 'PointedEars' Lahn <Po*********@web.de> wrote:
Effective to break where Exception handling is not supported? Yes.


What UA with any currency doesn't support exception handling?


I do not know what you mean by "with any currency", so I ignore that.

Exception handling (i.e. the `try' statement) is not supported by
IE/Windows (I do not know about IE/Mac) before version 5.0 (JScript
before version 5.0; current in browsers is 5.6) and Netscape before
version 6.0 (JavaScript before version 1.4; current in browsers is
1.6), for example. It has also been mentioned here that there are
mobile devices that do not support all ECMAScript 3 features of
which exception handling is one.

Furthermore, it turns out that there are different levels of support
for exception handling:

<URL:http://pointedears.de/scripts/js-version-info#try>

However, Michael has already pointed out that there is a
viable solution here without the need for exception handling
where the latter should always be the last resort.
Effective to submit the form anyway? Yes.


How so?


Because not the `submit' event of the `form' element is canceled but
the `click' event of a button is (or is not).

It should be <form ... onsubmit="return validateCat(this)"> instead
which is always reliable (client-side JS/ECMAScript support provided)
and requires no further language feature.
PointedEars
Dec 9 '05 #6
Thomas 'PointedEars' Lahn <Po*********@web.de> wrote:
I do not know what you mean by "with any currency", so I ignore that.
Basically my point is that yes, if one wants to support absolutely
every conceivable system, one must take extreme care. However, if one
decides that supporting the infinitesimal number of users still
saddled with abysmal UA's like IE 4 and NS 4 isn't worth the extra
effort, cleaner solutions can be devised. Again, I did not claim that
the code I posted was a good idea.
Furthermore, it turns out that there are different levels of support
for exception handling: <URL:http://pointedears.de/scripts/js-version-info#try>
That resource looks to be full of useful information. However, as
long as we're debating points of pedantry, the "toggle scroll" button
has no effect in Opera, and for whatever reason the table is unusable
in the default button state in IE 6.
However, Michael has already pointed out that there is a
viable solution here without the need for exception handling
where the latter should always be the last resort.
I will keep that in mind.
It should be <form ... onsubmit="return validateCat(this)"> instead
which is always reliable (client-side JS/ECMAScript support provided)
and requires no further language feature.


I noticed that only somewhat later. You're right.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Dec 10 '05 #7
Christopher Benson-Manica wrote:
Thomas 'PointedEars' Lahn <Po*********@web.de> wrote:
I do not know what you mean by "with any currency", so I ignore that.
Basically my point is that yes, if one wants to support absolutely
every conceivable system, one must take extreme care. However, if
one decides that supporting the infinitesimal number of users
still saddled with abysmal UA's like IE 4 and NS 4


It is impossible to call that number, but it is certainly not infinitesimal
small.
isn't worth the extra effort,
That person would probably not provide anything important, in both meanings.
cleaner solutions can be devised. Again, I did not claim that the code
I posted was a good idea.
ACK

What about

| It has also been mentioned here that there are mobile devices that do not
| support all ECMAScript 3 features of which exception handling is one.

?
Furthermore, it turns out that there are different levels of support
for exception handling:

<URL:http://pointedears.de/scripts/js-version-info#try>


That resource looks to be full of useful information.


Thanks, however I am still working on it. Any constructive information
regarding it is appreciated.
However, as long as we're debating points of pedantry,
I do not consider that to be one:
the "toggle scroll" button has no effect in Opera, and for whatever
reason the table is unusable in the default button state in IE 6.


That is strange as previous tests have shown that overflow:scroll
is supported by IE 6 (could you provide navigator.userAgent of the
browser you have tested with?). I will have to test that code again.
PointedEars
Dec 10 '05 #8
Thomas 'PointedEars' Lahn <Po*********@web.de> wrote:
What about | It has also been mentioned here that there are mobile devices that do not
| support all ECMAScript 3 features of which exception handling is one.
I've stopped digging :-)
That is strange as previous tests have shown that overflow:scroll
is supported by IE 6 (could you provide navigator.userAgent of the
browser you have tested with?). I will have to test that code again.


Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)

I also thought IE 6 recognized overflow: scroll, and I'm pretty sure
I've used it before myself. I'm not sure what might be the problem,
but in case it helps I've taken a high-resolution screenshot with my
IE version information and put it at http://ataru.gomen.org/files/ss.jpg.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Dec 11 '05 #9
Christopher Benson-Manica wrote:
Thomas 'PointedEars' Lahn <Po*********@web.de> wrote:
That is strange as previous tests have shown that overflow:scroll
is supported by IE 6 (could you provide navigator.userAgent of the
browser you have tested with?). I will have to test that code again.


Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)

I also thought IE 6 recognized overflow: scroll, and I'm pretty sure
I've used it before myself. I'm not sure what might be the problem,
but in case it helps I've taken a high-resolution screenshot with my
IE version information and put it at http://ataru.gomen.org/files/ss.jpg.


Thanks, that will help.
Regards,
PointedEars
Dec 11 '05 #10

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

Similar topics

1
by: Robert Nurse | last post by:
Hi All, I've got a form which I'm trying to submit automatically when the user has entered 2 or more characters in a text imput box. Here's my set up: <SCRIPT language="JavaScript1.2">...
1
by: Perttu Pulkkinen | last post by:
I have different functions that receive window.event as parameter. Functions are used like this: <input type="text" id="x" onkeypress="return onKeyCurrencyCheck(ev, 'x')" onblur...
6
by: rich_poppleton | last post by:
Help.... I've got a textarea where people type in a description. However for certain reasons we need to stop them typing !$*^ . I have a solution this which works fine in IE: function...
3
by: Raul M. Colon | last post by:
Is possible to assign a click event to a button control in a Web form just pressing the return key? Something like windows forms where you can assign this action to a default control. For example,...
6
by: Scott Lee | last post by:
I am displaying an ASP.Net generated form in a popup opened with window.showModalDialog. The form contains DropDownList controls. The first ddl is populated via databinding to a datatable, has...
18
by: len.hartley | last post by:
Hi, I am trying to pop-up a window when the user clicks on an image. The problem is that when the user clicks on the image and the window pops up OK, but the window underneath also proceeds to...
5
by: Robert S | last post by:
I am using the following to prevent the Enter key from submitting my form (this would have undesirable results): (index.html) <body onkeydown="rejectEnter( event )"> (functions.js) function...
4
by: Arnab das | last post by:
Below is the javascript code i am using function confirmDelete() { var returnValue = window.confirm("Deleting the current page. Continue?"); return returnValue; // var...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...
0
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...
0
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,...

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.