Is variable handling in mozilla different from IE?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • atomo

    Is variable handling in mozilla different from IE?

    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?



  • Thomas 'PointedEars' Lahn

    #2
    Re: Is variable handling in mozilla different from IE?

    atomo wrote:
    [color=blue]
    > echo"[/color]

    Shouldn't there be a whitespace character before the parameter of `echo'?
    [color=blue]
    > function check(){
    > if( ".$name.".value !=\"\" )
    > { code }";
    >
    > As you can see i set a variable name with PHP, and its value is checked in
    > javascript.[/color]

    The value of $name is the interesting part here.
    [color=blue]
    > Mozilla, shows an error on third line telling that the var is not defined,
    > stopping the execution.[/color]

    Well then probably it is not defined. Possibly you falsely
    assume server-side variables to be available client-side.
    [color=blue]
    > With IE and Opera there are no problems.[/color]

    Possibly the code before what you showed us yet is responsible for that.
    [color=blue]
    > I'm wondering if this is because IE supports defining a variable in the
    > condition, while mozilla doesn't.[/color]

    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.
    [color=blue]
    > Any ideas?[/color]

    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
    --[color=blue]
    > Why is it that I don't see the getElementByTag Name method in the
    > javascript reference in the newest version of dreamweaver (mx 2004)?[/color]
    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)

    Comment

    • atomo

      #3
      Re: Is variable handling in mozilla different from IE?

      [color=blue]
      > 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.[/color]


      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?



      Comment

      • Thomas 'PointedEars' Lahn

        #4
        Re: Is variable handling in mozilla different from IE?

        atomo wrote:
        ^^^^^^^^^^^^--------------------------.
        Who wrote that? Please include an attribution line.
        vvvvvvvvvvvvvvv[color=blue][color=green]
        >> 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.[/color]
        >
        > [...] 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?[/color]

        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

        Comment

        • Lee

          #5
          Re: Is variable handling in mozilla different from IE?

          atomo said:[color=blue]
          >
          >[color=green]
          >> 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.[/color]
          >
          >
          >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?[/color]

          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.

          Comment

          • atomo

            #6
            Re: Is variable handling in mozilla different from IE?

            hi again, the server source code:

            echo "<html>
            <script language=\"Java Script\">
            function reload(){
            if(".$name.".va lue!=\"\"){
            parent.fnc_cloc kstatus(1);}
            }

            The source received by the client:

            <html>
            <script language="JavaS cript">
            function reload(){
            if(c_ent_rut.va lue!=""){
            parent.fnc_cloc kstatus(1);}}

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

            if(typeof(".$na me.")==\"undefi ned\") {alert('undefin ed')};

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


            "Lee" <REM0VElbspamtr ap@cox.net> escribió en el mensaje
            news:bpth380293 5@drn.newsguy.c om...[color=blue]
            > atomo said:[color=green]
            > >
            > >[color=darkred]
            > >> 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.[/color]
            > >
            > >
            > >Thanks for your answer,
            > >
            > >I know maybe i'm trying to access a property of an undefined object, but[/color][/color]
            it[color=blue][color=green]
            > >seems like IE and Opera accept that and they interpretes that property[/color][/color]
            like[color=blue][color=green]
            > >"" (null) , while Mozilla doesn't accept that action. Am I right?[/color]
            >
            > I don't have Opera available, but IE 6 and Netscape 4 and 7 all throw[/color]
            errors[color=blue]
            > 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.
            >[/color]


            Comment

            • Lee

              #7
              Re: Is variable handling in mozilla different from IE?

              atomo said:[color=blue]
              >
              >hi again, the server source code:
              >
              > echo "<html>
              > <script language=\"Java Script\">
              > function reload(){
              > if(".$name.".va lue!=\"\"){
              > parent.fnc_cloc kstatus(1);}
              > }
              >
              >The source received by the client:
              >
              > <html>
              > <script language="JavaS cript">
              > function reload(){
              > if(c_ent_rut.va lue!=""){
              > parent.fnc_cloc kstatus(1);}}
              >
              >The error is pointed at the conditional if, c_ent_rut is not defined.
              >I just added the line:
              >
              > if(typeof(".$na me.")==\"undefi ned\") {alert('undefin ed')};
              >
              >With Mozilla the alert box is displayed, with IE no box appears and the
              >function works ok.
              >I'm totally confused.[/color]

              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.getEle mentById("c_ent _rut").value

              Comment

              • atomo

                #8
                Re: Is variable handling in mozilla different from IE?

                Thanx!!
                That solved it.

                "Lee" <REM0VElbspamtr ap@cox.net> escribió en el mensaje
                news:bptmmt02t3 b@drn.newsguy.c om...[color=blue]
                >
                > 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.getEle mentById("c_ent _rut").value
                >[/color]


                Comment

                • Lasse Reichstein Nielsen

                  #9
                  Re: Is variable handling in mozilla different from IE?

                  "atomo" <atomo@none.c l> writes:
                  [color=blue]
                  > 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:[/color]

                  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.
                  [color=blue]
                  > echo"
                  > function check(){
                  > if( ".$name.".value !=\"\" )
                  > { code }";[/color]

                  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.f orms['formId'].elements['elemName']"
                  [color=blue]
                  > As you can see i set a variable name with PHP, and its value is checked in
                  > javascript.[/color]

                  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.
                  [color=blue]
                  > Mozilla, shows an error on third line telling that the var is not defined,[/color]

                  Which var?
                  [color=blue]
                  > stopping the execution. With IE and Opera there are no problems.[/color]
                  [color=blue]
                  > I'm wondering if this is because IE supports defining a variable in the
                  > condition, while mozilla doesn't.[/color]

                  I doubt there is any difference in that.

                  /L
                  --
                  Lasse Reichstein Nielsen - lrn@hotpop.com
                  DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
                  'Faith without judgement merely degrades the spirit divine.'

                  Comment

                  Working...