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 2 of 2
  1. #1
    New Coder
    Join Date
    May 2009
    Posts
    48
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Dropdown Box: Value Change Confirmation

    Hi there, I am having a little problem trying to set this code up so that when I click on the drop down box, and select the 5th value down it should spit out text saying "Good Morning", and if it is anything else but value 5, "Bad Day".

    It seems it never spits out "Bad Day", and that is not making my day very good at all lol. So if anyone could help me correct this problem it would be greatly appreciated.

    var oQty=f['qty'+i];

    if (oQty = 5)
    document.write("Good morning!");
    }
    else
    {
    document.write("Bad day!");
    }

    <form action="" name="form" id="form">
    <div><span id="spryselect1">
    <label>Quantity:
    <select name="qty" id="qty">
    <option value="1">1 - $24.95</option>
    <option value="2">2 - $24.95</option>
    <option value="3">3 - $22.95</option>
    <option value="4">4 - $20.95</option>
    <option value="5">5 - $19.95</option>
    <option value="6">6 - $18.95</option>
    <option value="7">7 - $17.95</option>
    <option value="8">8 - $16.95</option>
    <option value="9">9 - $15.95</option>
    </select>
    </label>

    </form>

  • #2
    Regular Coder
    Join Date
    Feb 2009
    Location
    Wheeling, IL
    Posts
    358
    Thanks
    5
    Thanked 62 Times in 60 Posts
    Usually... when an if statement isn't working, look at what you're checking against:

    Code:
    if (oQty = 5)
    The code up there says... "If assigning 5 to oQty is a success, do whatever". What you need instead:

    Code:
    if (oQty == 5)
    See how that goes for you.
    The way to success is to assume that there are no impossible things. After all, if you think something is impossible, you will not even try to do it.

    How to ask smart questions?


  •  

    Posting Permissions

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