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 6 of 6
  1. #1
    New Coder
    Join Date
    Mar 2004
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    If statement proving true when it shouldn't.

    I am working on a page that has it's value read in through a database. One of the form's hidden fields is name "productName". In this field a value is imported from the database. I know this portion works becase I've use it on countless other pages and I display this field in another area of the page and the names are all read correctly.

    I am trying to test against the value of this field and execute a section of code if it's true. Here is what I have.

    Code:
    var sel = document.toppings;
    alert (sel.prodcutName.value);
    
    If (sel.productName.value = "Calzone')
    {
        alert (" I am executing");
       //do this stuff
    }
    Now if the first alerts shows "Calzone" then the second alert should show. The 2nd alert shows every single time regardless of what the first alert shows. This leads me to believe my if statement is not checking the value correctly and it probably has something to do with the quotes. I've tried using double " " on each side, but dreamweaver always replaces the 2nd " with '.

    Help?

  • #2
    Smokes a Lot
    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    1,594
    Thanks
    5
    Thanked 20 Times in 20 Posts
    Hello,

    Try changing

    If (sel.productName.value = "Calzone')

    to

    If (sel.productName.value = "Calzone" )


    You can use either syntax, (') or (") but you can't mix and match.
    Hope that helps,
    Basscyst
    Helping to build a bigger box. - Adam Matthews

  • #3
    New Coder
    Join Date
    Mar 2004
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I am using Dreamweaver MX and any time you use " " to surround a string, it changes the outter " to '.

    I opened up the file in notepad and it's showing "Calzone" instead of "Calzone' so it must just be a DW thing.

    Thanks for the help, but it's still not working.

  • #4
    New Coder
    Join Date
    Mar 2004
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If (sel.productName.value == 'Calzone')

    The double equal signs seem to work though I am not sure what they do. But it works so that's good. I'm off to figure out more about this equal sign phenominon.

  • #5
    Regular Coder
    Join Date
    Jul 2002
    Posts
    698
    Thanks
    0
    Thanked 0 Times in 0 Posts
    1 = sign is used to assign values to the variable to the left of it,

    2 = signs are used to test whether the left and rigth side are of the same value.

  • #6
    New Coder
    Join Date
    Mar 2004
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for that little tidbit of information. That should prove to be most usefull.


  •  

    Posting Permissions

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