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 to the CF scene
    Join Date
    Nov 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    if else if else getting error

    I am new to javascript and i added the cooding for the checkout page it's getting error.

    Kindly advice me to rectify the error.

    Thanks in advance.

    Code:
    <script>
    function submitFunction()
    {
    var country=document.getElementById("location");
    var currency=document.getElementById("money");
    if (country == 'India' && currency == 'INR')
    {
    alert ("thanks");
    }
    else if (country == 'India' && currency != 'INR')
    {
    alert("Change the currency as Indian Rupees");
    }
    else if (country != 'India' && currency == 'INR')
    {
    alert("Change the currency other than Indian Rupees");
    }
    else
    {
    alert("thanks");
    }
    
    }
    
    </script>
    </head>
    
    <body>
    
    <div id="#" style="height: 50px; margin-top:18px; margin-bottom: -15px;">
    <form method="get" action="" name="currencies">
    <select id="money" onchange="" name="currency" >
    <option value="USD">US Dollar</option>
    <option value="EUR">Euro</option>
    <option value="GBP">British Pound Sterling</option>
    <option value="CAD">Canadian Dollar</option>
    <option value="AUD">Australian Dollar</option>
    <option selected="selected" value="INR">Indian Rupees</option>
    </select>
    <input type="hidden" value="checkout" name="main_page">
    <input type="hidden" name="fecaction">
    </form>
    </div>
    
    <div id="checkoutShipto" class="floatingBox back">
    <address class="checkoutAddress">
    Raj M
    <br>
    32, Vinayagar Kovil Street
    <br>
    Mylapore, 600047
    <br>
    TN,India<div id="location">India</div>
    </address>
    </div>
    
    <div class="buttonRow forward">
    <input type="submit" onclick="submitFunction()" title="Confirm Order " alt="Confirm Order" value="submit" >
    </div>
    </div>
    Last edited by VIPStephan; 11-16-2013 at 03:19 PM. Reason: added code BB tags

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,102
    Thanks
    23
    Thanked 594 Times in 593 Posts
    You are getting the location correctly, but you are not extracting what is there. This is the correct way to get the information:
    Code:
    function submitFunction(){
    	var country = document.getElementById("location").innerHTML;
    	var currency = document.getElementById("money").value;
    Also note that you have an extra tag:
    Code:
    <div class="buttonRow forward">
    <input type="submit" onclick="submitFunction()" title="Confirm Order " alt="Confirm Order" value="submit" >
    </div>
    <!--</div>    THIS IS EXTRA TAG-->
    </body>
    </html>
    Welcome to the forums.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."


  •  

    Tags for this Thread

    Posting Permissions

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