Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Is variable handling in mozilla different from IE?

Reply
Thread Tools

Is variable handling in mozilla different from IE?

 
 
atomo
Guest
Posts: n/a
 
      11-24-2003
Hi, i got a problem with variable handling with mozilla(0.7). These lines
of code works fine on IE(6), but they doesn't on Mozilla:

echo"
function check(){
if( ".$name.".value!=\"\" )
{ code }";

As you can see i set a variable name with PHP, and its value is checked in
javascript.
Mozilla, shows an error on third line telling that the var is not defined,
stopping the execution. With IE and Opera there are no problems.
I'm wondering if this is because IE supports defining a variable in the
condition, while mozilla doesn't.

Any ideas?



 
Reply With Quote
 
 
 
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      11-24-2003
atomo wrote:

> echo"


Shouldn't there be a whitespace character before the parameter of `echo'?

> function check(){
> if( ".$name.".value!=\"\" )
> { code }";
>
> As you can see i set a variable name with PHP, and its value is checked in
> javascript.


The value of $name is the interesting part here.

> Mozilla, shows an error on third line telling that the var is not defined,
> stopping the execution.


Well then probably it is not defined. Possibly you falsely
assume server-side variables to be available client-side.

> With IE and Opera there are no problems.


Possibly the code before what you showed us yet is responsible for that.

> I'm wondering if this is because IE supports defining a variable in the
> condition, while mozilla doesn't.


As Sherlock Holmes would have said:
Do not try to conclude without having a proper premise.

Mozilla/5.0 *does* support that but the variable declaration is not
the problem. Instead, you are trying to access the property of an
undefined object.

> Any ideas?


Debug and, if that does not help, post the client-side code (after PHP
has parsed and replaced the server-side one), not the server-side code.
I recommend to use single quotes instead of double quotes in PHP
though, since you are already correctly using the `.' concatenation
operator of PHP.


PointedEars
--
> Why is it that I don't see the getElementByTagName method in the
> javascript reference in the newest version of dreamweaver (mx 2004)?

I'll blame whoever made dreamweaver. But I do that already, having seen
the Javascript it embeds in the pages it makes. (Lasse R. Nielsen, cljs)
 
Reply With Quote
 
 
 
 
atomo
Guest
Posts: n/a
 
      11-24-2003

> Mozilla/5.0 *does* support that but the variable declaration is not
> the problem. Instead, you are trying to access the property of an
> undefined object.



Thanks for your answer,

I know maybe i'm trying to access a property of an undefined object, but it
seems like IE and Opera accept that and they interpretes that property like
"" (null) , while Mozilla doesn't accept that action. Am I right?



 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      11-24-2003
atomo wrote:
^^^^^^^^^^^^--------------------------.
Who wrote that? Please include an attribution line.
vvvvvvvvvvvvvvv
>> Mozilla/5.0 *does* support [defining variables in a conditional
>> statement] that but the variable declaration is not the problem.
>> Instead, you are trying to access the property of an undefined
>> object.

>
> [...] I know maybe i'm trying to access a property of an undefined
> object, but it seems like IE and Opera accept that and they
> interpretes that property like "" (null) , while Mozilla doesn't
> accept that action. Am I right?


No, `null' (the null, empty or non-existent reference) has no properties
and it is not equal to "" (the empty string). If IE and Opera would
interpret the undefined variable as `null' or even `undefined', you
would also get a script error. You have not yet shown what the client
gets, so fruitless speculations are all that can be done here for now.


PointedEars
 
Reply With Quote
 
Lee
Guest
Posts: n/a
 
      11-24-2003
atomo said:
>
>
>> Mozilla/5.0 *does* support that but the variable declaration is not
>> the problem. Instead, you are trying to access the property of an
>> undefined object.

>
>
>Thanks for your answer,
>
>I know maybe i'm trying to access a property of an undefined object, but it
>seems like IE and Opera accept that and they interpretes that property like
>"" (null) , while Mozilla doesn't accept that action. Am I right?


I don't have Opera available, but IE 6 and Netscape 4 and 7 all throw errors
if you try to access a property of an undefined object.

You probably need to test if(typeof($name)=="undefined") before trying to
access the property.

 
Reply With Quote
 
atomo
Guest
Posts: n/a
 
      11-24-2003
hi again, the server source code:

echo "<html>
<script language=\"JavaScript\">
function reload(){
if(".$name.".value!=\"\"){
parent.fnc_clockstatus(1);}
}

The source received by the client:

<html>
<script language="JavaScript">
function reload(){
if(c_ent_rut.value!=""){
parent.fnc_clockstatus(1);}}

The error is pointed at the conditional if, c_ent_rut is not defined.
I just added the line:

if(typeof(".$name.")==\"undefined\") {alert('undefined')};

With Mozilla the alert box is displayed, with IE no box appears and the
function works ok.
I'm totally confused.


"Lee" <(E-Mail Removed)> escribió en el mensaje
news:(E-Mail Removed)...
> atomo said:
> >
> >
> >> Mozilla/5.0 *does* support that but the variable declaration is not
> >> the problem. Instead, you are trying to access the property of an
> >> undefined object.

> >
> >
> >Thanks for your answer,
> >
> >I know maybe i'm trying to access a property of an undefined object, but

it
> >seems like IE and Opera accept that and they interpretes that property

like
> >"" (null) , while Mozilla doesn't accept that action. Am I right?

>
> I don't have Opera available, but IE 6 and Netscape 4 and 7 all throw

errors
> if you try to access a property of an undefined object.
>
> You probably need to test if(typeof($name)=="undefined") before trying to
> access the property.
>



 
Reply With Quote
 
Lee
Guest
Posts: n/a
 
      11-24-2003
atomo said:
>
>hi again, the server source code:
>
> echo "<html>
> <script language=\"JavaScript\">
> function reload(){
> if(".$name.".value!=\"\"){
> parent.fnc_clockstatus(1);}
> }
>
>The source received by the client:
>
> <html>
> <script language="JavaScript">
> function reload(){
> if(c_ent_rut.value!=""){
> parent.fnc_clockstatus(1);}}
>
>The error is pointed at the conditional if, c_ent_rut is not defined.
>I just added the line:
>
> if(typeof(".$name.")==\"undefined\") {alert('undefined')};
>
>With Mozilla the alert box is displayed, with IE no box appears and the
>function works ok.
>I'm totally confused.


It looks like you've got a page element named "c_ent_rut". IE will
allow you to refer to that element by name, but reasonable browsers
will require you to fully qualify the reference to avoid confusion.

If you want all browsers to find that object, you will need to use
a more standard way of referring to it, such as:
document.getElementById("c_ent_rut").value

 
Reply With Quote
 
atomo
Guest
Posts: n/a
 
      11-24-2003
Thanx!!
That solved it.

"Lee" <(E-Mail Removed)> escribió en el mensaje
news:(E-Mail Removed)...
>
> It looks like you've got a page element named "c_ent_rut". IE will
> allow you to refer to that element by name, but reasonable browsers
> will require you to fully qualify the reference to avoid confusion.
>
> If you want all browsers to find that object, you will need to use
> a more standard way of referring to it, such as:
> document.getElementById("c_ent_rut").value
>



 
Reply With Quote
 
Lasse Reichstein Nielsen
Guest
Posts: n/a
 
      11-24-2003
"atomo" <(E-Mail Removed)> writes:

> Hi, i got a problem with variable handling with mozilla(0.7). These lines
> of code works fine on IE(6), but they doesn't on Mozilla:


Check this page:
<URL:http://www.mozilla.org/docs/web-developer/upgrade_2.html>
(Previously known as: "Upgrading Your Web Content for Mozilla and
Netscape 6").
It lists the most common features of other browsers that isn't
standard and doesn't work in Mozilla.

> echo"
> function check(){
> if( ".$name.".value!=\"\" )
> { code }";


My guess is that what is contained in $name is just the name of
the element, not a proper reference to it.
A proper reference would be
"document.forms['formId'].elements['elemName']"

> As you can see i set a variable name with PHP, and its value is checked in
> javascript.


It is pretty hard, going on impossible, to guess what the content of your
$name variable is, and that is what is important for this question. Also,
not everybody understands PHP, so you should show us the *actual* HTML/
Javascript that is sent to the browser. Then we'll find the problem in no
time.

> Mozilla, shows an error on third line telling that the var is not defined,


Which var?

> stopping the execution. With IE and Opera there are no problems.


> I'm wondering if this is because IE supports defining a variable in the
> condition, while mozilla doesn't.


I doubt there is any difference in that.

/L
--
Lasse Reichstein Nielsen - http://www.velocityreviews.com/forums/(E-Mail Removed)
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
signal handling and (structured) exception handling Peter C++ 34 10-17-2009 10:03 AM
python list handling and Lisp list handling Mark Tarver Python 22 04-26-2009 09:36 PM
Is faster handling hexadecimal values than handling chars? Iñaki Baz Castillo Ruby 1 04-15-2008 09:04 AM
"Variable variable name" or "variable lvalue" mfglinux Python 11 09-12-2007 03:08 AM
How do I scope a variable if the variable name contains a variable? David Filmer Perl Misc 19 05-21-2004 03:55 PM



Advertisments