If statement: != does not work

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • weblinkunlimited@gmail.com

    If statement: != does not work

    Hello,

    Can someone help me.
    'number' is a string and not a number!
    Why does the following not work:

    <script type='text/javascript'>

    function calculate(rij) {

    var number = "0";

    if(number!="0") {
    for(var i=0; i<description.l ength; i++) {
    if(description[i] == descr) {
    var arrrow=i;
    }
    }
    )
    }
    </script>

    I also tried:
    if(number>"0") {

    But because number is a string, that did not help much (you have to
    try sometimes a few things).
    The above source-code is part of a PHP-script (I replace the \" in "),
    but that should not matter.
    When the PHP-code has been started, I see an error in my IE at the
    left bottom of the window (Error on page / Done). When I run the above
    script only, I do not get an error. But when I add a line
    alert("test"); before </script>, I do not see the alert, that alerts
    me that there is an error.

    I hope you have enough information to see what i did wrong.

    Thank you in advance!
  • Evertjan.

    #2
    Re: If statement: != does not work

    wrote on 12 mrt 2008 in comp.lang.javas cript:
    Why does the following not work:
    >
    <script type='text/javascript'>
    >
    function calculate(rij) {
    >
    var number = "0";
    >
    if(number!="0") {
    for(var i=0; i<description.l ength; i++) {
    if(description[i] == descr) {
    var arrrow=i;
    }
    }
    )
    The ) must be a }

    Please do not just say "does not work",
    but state the error line and code.

    }
    </script>
    >
    The above source-code is part of a PHP-script
    It is not, it is plain clientside javascript.
    (I replace the \" in "),
    ??
    but that should not matter.
    When the PHP-code has been started,
    The PHP code, should have been finished by then,
    because that runs on the server and just manipulates
    the html stream sent to the client.

    So please look at and perhaps send us [part of] the view source code
    that the browser received. The code as submitted to the PHP engine on the
    browser is not of interest to us in this NG, and your error is
    clientside.
    I see an error in my IE at the
    left bottom of the window (Error on page / Done).
    What browser?

    If it is IE you shoud double click the error icon to read the error
    When I run the above
    script only, I do not get an error.
    Compare both view source codes.

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)

    Comment

    • dave

      #3
      Re: If statement: != does not work

      On Mar 12, 1:52 pm, weblinkunlimi.. .@gmail.com wrote:
      Hello,
      >
      Can someone help me.
      'number' is a string and not a number!
      Why does the following not work:
      >
      <script type='text/javascript'>
      >
      function calculate(rij) {
      >
      var number = "0";
      >
      if(number!="0") {
      for(var i=0; i<description.l ength; i++) {
      if(description[i] == descr) {
      var arrrow=i;
      }
      }
      )
      }
      </script>
      >
      I also tried:
      if(number>"0") {
      >
      But because number is a string, that did not help much (you have to
      try sometimes a few things).
      The above source-code is part of a PHP-script (I replace the \" in "),
      but that should not matter.
      When the PHP-code has been started, I see an error in my IE at the
      left bottom of the window (Error on page / Done). When I run the above
      script only, I do not get an error. But when I add a line
      alert("test"); before </script>, I do not see the alert, that alerts
      me that there is an error.
      >
      I hope you have enough information to see what i did wrong.
      >
      Thank you in advance!
      I'll give you a hint, run the code in Firefox and look at the
      javascript error log. That will help you find the error.

      Comment

      • weblinkunlimited@gmail.com

        #4
        Re: If statement: != does not work

        Ervertjan,
        The ) must be a }
        Thank you for the second time!!!

        With your help with my previous question, everything works very
        well!!!

        Ramin

        Comment

        • RobG

          #5
          Re: If statement: != does not work

          On Mar 13, 6:52 am, weblinkunlimi.. .@gmail.com wrote:
          Hello,
          >
          Can someone help me.
          'number' is a string and not a number!
          Why does the following not work:
          >
          <script type='text/javascript'>
          >
          function calculate(rij) {
          >
          var number = "0";
          >
          if(number!="0") {
          It seems to me that will always return false and the block statement
          will never be executed.


          --
          Rob

          Comment

          Working...