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 4 of 4
  1. #1
    Regular Coder
    Join Date
    Oct 2005
    Location
    Surrey, England
    Posts
    286
    Thanks
    2
    Thanked 2 Times in 2 Posts

    Just an onload quickie!

    Hi,

    What I need to do is when the page loads, focus on a select option asif the user clicked the option..

    I have limited ability to edit the script i'm trying to fix but essentially i have the code

    Code:
    <select name="country"><option value="uk">United Kingdom</option></select>
    The old select menu used to have every country as a shipping option but i have managed to strip it down to 1 country. In order to add the shipping to the order you need to physically select the country (because the price which shows up on the cart page is driven by an "onchange" event i think).

    So the best way i can think around this would be to select the option onload maybe?

    Im not entirely sure but i bet its probably just a 1 line fix.

    Like i said, i have limited ability to edit code. I can edit the raw html (parts of) of that page but i cant change any of the javascript, ajax, php etc...

    Thanks.

    http://www.sailorjerrystore.co.uk (try adding the first product in the catalogue to the cart and you will understand the shipping problem.)
    Daniel Warner
    - - - - - - - - - -
    GuitarMart.co.uk - Free Online Classified Advertisement for Guitarists in the United Kingdom. Free Ads with a Free Photo.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,310
    Thanks
    203
    Thanked 2,563 Times in 2,541 Posts
    Code:
    <select name="country">
    <option value="uk" selected>United Kingdom</option>
    </select>
    But clearly this will not work if the price etc. is driven by the onchange event as there has been no change.

    The simplest solution (a kludge really) is probably:-

    Code:
    <select name="country">
    <option value = "" selected>Choose a country</option>
    <option value = "uk">United Kingdom</option>
    </select>

    Ninety-eight percent of the adults in this country are decent, hard-working, honest Englishmen. It's the other lousy two percent that get all the publicity. But then - we elected them.

  • #3
    Regular Coder
    Join Date
    Oct 2005
    Location
    Surrey, England
    Posts
    286
    Thanks
    2
    Thanked 2 Times in 2 Posts
    That is basically what i already have. I was looking for a line of javascript which would dynamically select the option "united kingdom" for me. This way, the price and the option would be selected every time the page loads.

    Currently, the selected value "United Kingdom" will always return to "Please Select" whenever you refresh the page.

    Any ideas?
    Daniel Warner
    - - - - - - - - - -
    GuitarMart.co.uk - Free Online Classified Advertisement for Guitarists in the United Kingdom. Free Ads with a Free Photo.

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,310
    Thanks
    203
    Thanked 2,563 Times in 2,541 Posts
    You seem to have in mind:-

    Code:
    <body onload = "select()">
    
    <select name="country" id ="country">
    <option value="uk">United Kingdom</option>
    </select>
    
    <script type = "text/javascript">
    function select() {
    var ref = document.getElementById("country");
    ref.options[0].selected = true;
    }
    </script>

    But as before clearly this will not work if the price etc. is driven by the onchange event as there has been no change. You really need to alter the PHP code.


  •  

    Posting Permissions

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