SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Member
    Join Date
    Apr 2013
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to get the selected value after redirect in given website.

    Look at the website:http://weconvex.com/

    The drop down section left to twitter and linkedin symbols. In this, when i choose any option, it goes to that given url but default value of select box does not change. How to change the value according to that.

    For example, I choose United States, it redirects to the http://weconvex.com/united-states but values of the select box remains australia. How to correct it. Does it need any jquery code? Please explain in detail.

    Seed Analytics – United States.png

    Thanks.

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,313
    Mentioned
    178 Post(s)
    Tagged
    8 Thread(s)
    Hi,

    Quote Originally Posted by vny.009 View Post
    How to correct it. Does it need any jquery code? Please explain in detail.
    Just use the selected attribute to select the option that should be displayed on page load.

    E.g.

    Code:
    <select>
     <option value="">Australia</option>
     <option value="" selected>United states</option>
     <option value="">Singapore</option>
     <option value="">India</option>
    </select>

  3. #3
    SitePoint Member
    Join Date
    Apr 2013
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you checked my site http://weconvex.com.
    In that, at the top left to twitter symbol. I have tried it. But not working. Many people said it will not work after page load.

    Do you know any other solution?

  4. #4
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,313
    Mentioned
    178 Post(s)
    Tagged
    8 Thread(s)
    Quote Originally Posted by vny.009 View Post
    Have you checked my site http://weconvex.com.
    Yes.

    Quote Originally Posted by vny.009 View Post
    In that, at the top left to twitter symbol. I have tried it. But not working. Many people said it will work after page load.
    What did you try?
    How is it not working?

    It would help if you could be a little more specific

  5. #5
    SitePoint Member
    Join Date
    Apr 2013
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    okay. i have used only a onchange event handler like this when a option is selected.

    Code:
    <select onchange="test(this.options[this.selectedIndex].value)" style="width:120px">
    and a small js function which is mostly worthless.
    Code:
    <script type="text/javascript">
    function test(url) {
    window.location = url.toString();
    
    }
    </script>
    And I have a another helping site http://10kya.com

    In that site, check the currency changer in top right. I want the same functionality like this currency changer.

  6. #6
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,313
    Mentioned
    178 Post(s)
    Tagged
    8 Thread(s)
    On your original site, when you select an option from the dropdown menu, your JS code is redirecting you to a new url (using window.location).
    Doesn't this mean that you are loading a new page?

  7. #7
    SitePoint Member
    Join Date
    Apr 2013
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, I know i am loading new page. If there any solution for this?
    If you know the solution with the ajax page load. Please share.

  8. #8
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,313
    Mentioned
    178 Post(s)
    Tagged
    8 Thread(s)
    Quote Originally Posted by vny.009 View Post
    Yes, I know i am loading new page.
    On your new page then, do this:

    Code:
    <select>
     <option value="">Australia</option>
     <option value="" selected>United states</option>
     <option value="">Singapore</option>
     <option value="">India</option>
    </select>
    Whereby you add the selected attribute to whichever option should be pre-selected.
    Unless I'm missing something, it is that simple

  9. #9
    SitePoint Member
    Join Date
    Apr 2013
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I could do that but problem is this is in a single file "header.php". I think this can be achieved with jquery ajax. I am weak in js. So, if you know jquery ajax, You can create a code.
    Thanks for the replies.

  10. #10
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,313
    Mentioned
    178 Post(s)
    Tagged
    8 Thread(s)
    Ah, ok, now I understand.

    Sure you can do this with JavaScript.
    I'll use jQuery, because you are including it on the page anyway, but it's not really necessary.
    For this to work, you need to give the select element a unique id (e.g. "mySelect") and the values of the option elements must be the same format as the url

    Code JavaScript:
    $(function(){
      $("#mySelect > option").each(function() {
        if(this.value == window.location.pathname){
          this.selected = 'selected';
        }
      });
    });


Tags for this Thread

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
  •