Is variable handling in mozilla different from IE?

Discussion in 'Javascript' started by atomo, Nov 24, 2003.

  1. atomo

    atomo Guest

    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?
     
    atomo, Nov 24, 2003
    #1
    1. Advertising

  2. 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)
     
    Thomas 'PointedEars' Lahn, Nov 24, 2003
    #2
    1. Advertising

  3. atomo

    atomo Guest


    > 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?
     
    atomo, Nov 24, 2003
    #3
  4. 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
     
    Thomas 'PointedEars' Lahn, Nov 24, 2003
    #4
  5. atomo

    Lee Guest

    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.
     
    Lee, Nov 24, 2003
    #5
  6. atomo

    atomo Guest

    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" <> escribió en el mensaje
    news:...
    > 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.
    >
     
    atomo, Nov 24, 2003
    #6
  7. atomo

    Lee Guest

    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
     
    Lee, Nov 24, 2003
    #7
  8. atomo

    atomo Guest

    Thanx!!
    That solved it.

    "Lee" <> escribió en el mensaje
    news:...
    >
    > 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
    >
     
    atomo, Nov 24, 2003
    #8
  9. "atomo" <> 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 -
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
    'Faith without judgement merely degrades the spirit divine.'
     
    Lasse Reichstein Nielsen, Nov 24, 2003
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Henri
    Replies:
    9
    Views:
    1,846
    Toby Inkster
    Feb 22, 2005
  2. tshad
    Replies:
    35
    Views:
    1,336
    Beauregard T. Shagnasty
    May 19, 2005
  3. Michael Sgier

    IE different than Mozilla

    Michael Sgier, Aug 19, 2006, in forum: HTML
    Replies:
    3
    Views:
    353
    Neredbojias
    Aug 19, 2006
  4. Macamba
    Replies:
    1
    Views:
    124
    Jim Ley
    Jan 17, 2004
  5. Replies:
    4
    Views:
    92
    Martin Honnen
    Jul 4, 2004
Loading...

Share This Page