Welcome our webmaster and SEO forum
Please enjoy the forum, contribute what you can, and wind up the Moderators!
Results 1 to 6 of 6

Thread: Country selection using dropdown.

  1. #1
    MWoods's Avatar
    MWoods is offline Junior Member
    Join Date
    Jun 2009
    Location
    Nottingham.
    Posts
    4

    Default Country selection using dropdown.

    Hi. My first post here.

    I have an established site but would like to improve a checkout page. On it I have java code to calculate appropriate postage rate.

    Currently I have UK, Europe and World radio inputs but would like a drop down of all countries to return the relevant postage zone rate for the existing Javascript code;

    Select Your Carriage:


    <input type="radio"
    checked name="cost3" value="0"
    onclick="typeOfCarriage('uk');calculate()">
    UK
    <input type="radio" name="cost3" value="3"
    onclick="typeOfCarriage('europe');calculate()">
    Europe
    <input type="radio"
    name="cost3" value="4.5"
    onclick="typeOfCarriage('world');calculate()">
    World
    <input type="button" name="calcButton"
    value="Calculate Total" onclick="calculate()"><br><br>
    <div align=center><b></h2><h4>Total: English Pounds GBP </b>
    <input
    type="text" size="7" name="cost" value="0"
    onfocus="setTimeout('defocus()',1)">


    If anyone more in the know could suggest how a dropdown of countries could be used instead of this radio method I would be very grateful, please?!

    Cheers, Mark (Nottingham).
    Last edited by MWoods; 06-03-2009 at 07:25 PM. Reason: not able to link to site

  2. #2
    craftyclicks is offline Junior Member
    Join Date
    Jun 2009
    Location
    Maidenhead, UK
    Posts
    8

    Default

    You can get a full list of countries by grabbing a piece of something like osCommerce. Once you have the drop down list you can attach an onchange or onclick event to it and handle it a similar same way as before - i.e. call

    typeOfCarriage(this.selectedIndex);calculate();

    There will now be a lot more different shipping rates to figure out! In the function typeOfCarriage in place of the string it took before you will now get an int and you can have a case switch to do different things depending on the selected country.

    Hope this makes sense.

  3. #3
    MWoods's Avatar
    MWoods is offline Junior Member
    Join Date
    Jun 2009
    Location
    Nottingham.
    Posts
    4

    Default Thanks

    for the VERY prompt reply, Craftyclicks!

    I'm afraid I know very little about Javascript - I have the list of countries as options already on my page elsewhere but at the moment I believe there are only radio, button, label or form options for "input type".

    Could you find time to explain to me how a Java-fool such as myself could create the required drop down menu, please? Functions and the calling of them is a dark art to me.

    Cheers, Mark.

  4. #4
    craftyclicks is offline Junior Member
    Join Date
    Jun 2009
    Location
    Maidenhead, UK
    Posts
    8

    Default

    Tried to PM you, but turns out I'm to new to this forum for this ;-)

    OK,

    No problem. I see what you are after. Have a look at
    www dot craftyclicks dot co dot uk/downloads/samples_action/oscommerce/create_account.php

    This is not exactly what you are after, but notice how the country dropdown behaves - if you select anything but UK, the 'Find Address' button disappears.

    Your handler could do some maths rather than hide buttons.

    I can send you the code for this tomorrow. Let me know your email address. I'm on adam at craftyclicks dot co dot uk.

    Cheers,
    Adam

  5. #5
    craftyclicks is offline Junior Member
    Join Date
    Jun 2009
    Location
    Maidenhead, UK
    Posts
    8

    Default

    Hi Mark,

    Had a quick look at your site html. Here is what should do the job:

    1. Modify JS function calculate and add one new function as such:

    Code:
    function calculate() {
      basicprice = roundOff(Number(CheckNull(document.BuyForm.qty1.value) * document.BuyForm.cost1.value));
    
      document.BuyForm.cost.value = roundOff(Number(basicprice) + Number(document.BuyForm.carriage_amount.value));
      document.BuyForm.cost1.value = 9.99;
    }
    
    function calculate_new(ship_price) {
      basicprice = roundOff(Number(CheckNull(document.BuyForm.qty1.value) * document.BuyForm.cost1.value));
      document.BuyForm.cost.value = roundOff(Number(basicprice) + Number(ship_price));
      document.BuyForm.cost1.value = 9.99;
      document.BuyForm.carriage_amount.value = Number(ship_price);
    }
    2. Add the country drop down list as such:

    HTML Code:
    <select name="country" onclick="calculate_new(this.value);" onchange="calculate_new(this.value);">
    <option value="2.00">Germany</option>
    <option value="0.00" SELECTED>United Kingdom</option>
    <option value="2.50">United States</option>
    </select>
    3. Add more countries to your list. You can grab a list off Wikipedia (en dot wikipedia.org/wiki/ISO_3166-1).

    I tried not to change your JS too much in case something else relies on it too.

    Hope this works for you.

    Adam

  6. #6
    MWoods's Avatar
    MWoods is offline Junior Member
    Join Date
    Jun 2009
    Location
    Nottingham.
    Posts
    4

    Default Code now integrated.

    A quick note to thank you SO much again, Adam!

    I appear to now have a customer-friendly payment page!

    You are a star!

    Many thanks for your help - I'd never have done it without you..

    Cheers, Mark.


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124