Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 15 of 15
  1. #1
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unterminated String Constant on cell value

    Hello All,

    I'm trying to get the cell values from my column and apply a background color based on the value..simple task. For some reason I am getting a "Unterminated String Constant" when I run the logic, which doesnt work btw. Can any tell me what this means exactly, and how I can overcome it?

    Code:
     
    
       var rows = document.getElementById("trans_separate").getElementsByTagName("tbody")[0].getElementsByTagName("tr");
            //alert(rows.length);
    
    
            for (i = 0; i < rows.length; i++) {
                cells = rows[i].getElementsByTagName('td');
    			
               if (cells[14].textContent === 'R') rows[i].className = "red";
    
               else if (cells[14].textContent === 'Y') rows[i].className = "yellow";
    
              else if (cells[14].textContent === 'N') rows[i].className = "green";
    				
            }

  • #2
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    Don't use the === comparator. Use ==.

    If the row already has a class, this will replace it. If you want to add the className to the row, rows[i].className += "red";

    Not sure if textContent will work. Did you try innerHTML?
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #3
    Regular Coder
    Join Date
    Jan 2013
    Location
    Germany
    Posts
    578
    Thanks
    4
    Thanked 77 Times in 77 Posts
    Quote Originally Posted by WolfShade View Post
    Don't use the === comparator. Use ==.
    Would you add an explanation for this recommendation?

  • #4
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    http://stackoverflow.com/questions/3...operator-i-use

    Scroll to Bill The Lizard's answer.
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #5
    Regular Coder
    Join Date
    Jan 2013
    Location
    Germany
    Posts
    578
    Thanks
    4
    Thanked 77 Times in 77 Posts
    I don't know if we're reading different answers, but he clearly states that === is never inferior to ==, but superior in some cases. So I don't really understand why you'd actively recommend not to use ===.

    He also explicitly quotes Douglas Crockford:

    My advice is to never use the evil twins. Instead, always use === and !==.

  • #6
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    "evil twins", indeed.

    Just before Crockford's quote: The == operator will compare for equality after doing any necessary type conversions. The === operator will not do the conversion, so if two values are not the same type === will simply return false. It's this case where === will be faster, and may return a different result than ==. In all other cases performance will be the same.

    new String["123"] is not the same as "123". The === will report false. == is slower due to conversion, but the performance hit isn't even worth mentioning. Maybe 10 years ago, the gain with === might have been a big thing.. but with today's browsers and CPUs..
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #7
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,965
    Thanks
    0
    Thanked 236 Times in 233 Posts
    I don't see any "Unterminated String Constant" error in the posted code. Maybe the error is in the other blocks of code?

    Debugging with Firebug will surely help you quickly pinpoint where the error is.

  • #8
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    It just occurred to me; if the OP is getting an unterminated string constant, could the value within the cell contain a line break? That would certainly break the string.
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #9
    Regular Coder
    Join Date
    Jan 2013
    Location
    Germany
    Posts
    578
    Thanks
    4
    Thanked 77 Times in 77 Posts
    @ WolfShade

    I yet fail to see an actual reason to favor ==. All I see is a reason not to recommend === to someone who used ==. But what's so bad about === that you actively need to recommend using ==?

    Performance is not the issue with === versus == anyway. Did you read what Crockford said? == is dangerous, it's not even transitive thus evil twins. As Crockford says, it's simply cleaner and safer to use ===.

  • #10
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,965
    Thanks
    0
    Thanked 236 Times in 233 Posts
    Quote Originally Posted by WolfShade View Post
    It just occurred to me; if the OP is getting an unterminated string constant, could the value within the cell contain a line break? That would certainly break the string.
    It should not throw an error even if the cell content has line breaks.

  • #11
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    Quote Originally Posted by Airblader View Post
    @ WolfShade

    I yet fail to see an actual reason to favor ==. All I see is a reason not to recommend === to someone who used ==. But what's so bad about === that you actively need to recommend using ==?

    Performance is not the issue with === versus == anyway. Did you read what Crockford said? == is dangerous, it's not even transitive thus evil twins. As Crockford says, it's simply cleaner and safer to use ===.
    Then we agree to disagree. Matter of preference, if you like. Use whatever you like; unless it is absolutely necessary to use === and !==, I will use == and !=, regardless of what Crockford says.
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #12
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,731
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    Quote Originally Posted by WolfShade View Post
    Then we agree to disagree. Matter of preference, if you like. Use whatever you like; unless it is absolutely necessary to use === and !==, I will use == and !=, regardless of what Crockford says.
    I have to say that I feel the same as Wolfshade. I know that purists prefer === but there is no >== or <==. So what about (say) if "1" <== "2"? I have yet to be convinced that === has any real or perceptible advantage over == (unless of course you actually do want to compare for identity - I don't recall any occasion where this has in fact been necessary for me). Crockford is very much an authority to be respected but he is not the Pope.

    So long as you understand the implications, == is fine for most uncontrived situations.
    Last edited by Philip M; 03-20-2013 at 10:07 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #13
    Regular Coder
    Join Date
    Jan 2013
    Location
    Germany
    Posts
    578
    Thanks
    4
    Thanked 77 Times in 77 Posts
    Quote Originally Posted by WolfShade View Post
    unless it is absolutely necessary to use === and !==, I will use == and !=, regardless of what Crockford says.
    Which is completely fine. I just didn't (still don't) get what the reasoning behind explicitly telling someone to get rid of === is it's not "worse" in any way.

  • #14
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    If what you are comparing to isn't the same type, it will fail. That doesn't seem "worse", to you? Letting the browser perform the conversion, versus manually scripting a conversion (if needed) is "worse", in your opinion?

    Letting the browser do the conversion: lazy, perhaps.. but "worse"? Again, if the performance hit were something like 500ms instead of 5ms (granted, arbitrary numbers), I might agree with your stance.

    In the meantime, I've tried letting you have your opinion and walk away. Yet you keep dragging me back.

    Fin?
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #15
    Regular Coder
    Join Date
    Jan 2013
    Location
    Germany
    Posts
    578
    Thanks
    4
    Thanked 77 Times in 77 Posts
    Quote Originally Posted by WolfShade View Post
    If what you are comparing to isn't the same type, it will fail. That doesn't seem "worse", to you?
    No, because if they don't have the same type, they aren't equal that's how most other languages handle it, so it really isn't a big surprise. And even JS developers should at least know that there is something like different types.

    And my argument would be: The identity(!) operator not being transitive. That doesn't seem "worse" to you? I mean that really is something you won't find in other languages. And it's something that goes completely against intuition.

    But actually, as I said before, I never tried to argue (in this thread, at least) that === is better than ==. I only tried to argue that === isn't worse than ==, because if they would be equally good (or, as you said, if it'd be a matter of personal preference), then there wouldn't be a reason to tell someone not to use === if he used it. At least not with a "shouldn't use" in that sentence, because it suggests that there is something wrong or bad about it.

    Letting the browser do the conversion: lazy, perhaps
    For Philip's record: I didn't say that word once in this thread.

    So what I take is that this is your opinion: "== is absolutely fine if you know about its implications, but === isn't good because there are implications you have to know about". All I wanted was to understand why you recommended ==, to see if there was a reason I didn't know, I don't care if you change your opinion or not.
    But knowing that there is no actual reason (in my opinion!), my recommendation for @OP is: Keep using ===. That way, he got several opinions and can choose which one suits him more.

    Fin.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •