SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    146
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy javascript problem with droplist

    Hi I made a script with droplist for choosing card type. If Master card is beening chosed then tax fee shows 4, otherwise 0. But I got the result is whatever I choose the tax fee shows 4. Is anyone know what's the problem?


    <html>
    <head>
    <script type="text/javascript">
    function favBrowser()
    {
    var cardtype=document.getElementById("cardType")
    if (cardtype='Master Card')
    {
    taxfee = 200 * 0.02
    }
    else
    {
    taxfee=0
    }
    document.getElementById("tax").value=taxfee

    }
    </script>
    </head>
    <body>
    <form>
    Card Type*:
    <select id="cardType" onchange="favBrowser()">
    <option></option>
    <option>Master Card</option>
    <option>Visa Debit, Delta or Connect</option>
    <option>Visa</option>
    <option>Switch/UK Maestro</option>
    <option>Solo</option>
    <option>JCB</option>
    </select>
    <p>Amount: 200</p>

    <p>Tax: <input type="text" id="tax" size="20"></p>
    </form>
    </body>
    </html>

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <html>
    <head>
    <script type="text/javascript">
    function favBrowser(obj)
    {
    var cardtype = obj.options[obj.selectedIndex].value;
    if (cardtype == 'Master Card')
    {
    taxfee = 200 * 0.02
    }
    else
    {
    taxfee=0
    }
    document.getElementById("tax").value=taxfee
    
    }
    </script>
    </head>
    <body>
    <form>
    Card Type*:
    <select id="cardType" onchange="favBrowser(this)">
    <option></option>
    <option>Master Card</option>
    <option>Visa Debit, Delta or Connect</option>
    <option>Visa</option>
    <option>Switch/UK Maestro</option>
    <option>Solo</option>
    <option>JCB</option>
    </select>
    <p>Amount: 200</p>
    
    <p>Tax: <input type="text" id="tax" size="20"></p>
    </form>
    </body>
    </html>
    cheers

  3. #3
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <html>
    <head>
    <script type="text/javascript">
    function favBrowser(obj)
    {
    var cardtype = obj.options[obj.selectedIndex].value;
    if (cardtype == 1)
    {
    taxfee = 200 * 0.02
    }
    else
    {
    taxfee=0
    }
    document.getElementById("tax").value=taxfee
    
    }
    </script>
    </head>
    <body>
    <form>
    Card Type*:
    <select id="cardType" onchange="favBrowser(this)">
    <option value="1">Master Card</option>
    <option value="2">Visa Debit, Delta or Connect</option>
    <option value="3">Visa</option>
    <option value="4">Switch/UK Maestro</option>
    <option value="5">Solo</option>
    <option value="6">JCB</option>
    </select>
    <p>Amount: 200</p>
    
    <p>Tax: <input type="text" id="tax" size="20"></p>
    </form>
    </body>
    </html>
    cheers

  4. #4
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    146
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks!!! :d


Bookmarks

Posting Permissions

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