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

Is variable handling in mozilla different from IE?

P: n/a
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?

Jul 20 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
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)
Jul 20 '05 #2

P: n/a
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?

Jul 20 '05 #3

P: n/a
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
Jul 20 '05 #4

P: n/a
Lee
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.

Jul 20 '05 #5

P: n/a
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" <RE**************@cox.net> escribió en el mensaje
news:bp*********@drn.newsguy.com...
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 itseems 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.

Jul 20 '05 #6

P: n/a
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

Jul 20 '05 #7

P: n/a
Thanx!!
That solved it.

"Lee" <RE**************@cox.net> escribió en el mensaje
news:bp*********@drn.newsguy.com...

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

Jul 20 '05 #8

P: n/a
"atomo" <at***@none.cl> 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 - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.