SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    May 2008
    Location
    Boiling Springs, NC, USA
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Selecting drop-down box option based on parameters in URL

    I would like to be able to have a parameter in a URL that chooses the "Selected" item in a drop down box when the page loads.

    For instance, the url would be something like -- page.html?centerName=center1 or ?centerName=center2 etc.
    Then, when the page loads, depending on what the parameter is, that particular center would be chosen automatically (pre-filled) into the drop down menu that is an input field for a form.


    Here is the link to the page I'm trying to accomplish this on.

    Is something like this possible?


    thanks for any help or ideas. Cheers!

  2. #2
    SitePoint Evangelist stef25's Avatar
    Join Date
    Nov 2004
    Location
    belgium
    Posts
    465
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    basically what you do is put the element you want from the url in a variable, and then you use: if var = "x" > set select attribute of option element to "selected".

    the first part is sort of explained here and the second part can be done quite easily with jquery or another js library

    keep in mind you can also do this on the server side which may be better since JS doesnt have to be enabled in the browser. in this case you use the $_GET parameters and another if > then statement to print out selected="selected" in your option tag
    I need someone to protect me from
    all the measures they take in order to protect me

  3. #3
    SitePoint Member
    Join Date
    May 2008
    Location
    Boiling Springs, NC, USA
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I gave up on the select box solution, changed to just filling a text box from a passed variable instead. Works like a charm.


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
  •