Is variable handling in mozilla different from IE?

A

atomo

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?
 
T

Thomas 'PointedEars' Lahn

atomo said:

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)
 
A

atomo

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?
 
T

Thomas 'PointedEars' Lahn

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
 
L

Lee

atomo said:
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.
 
A

atomo

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.
 
L

Lee

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
 
L

Lasse Reichstein Nielsen

atomo said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top