SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2009
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Drop-down with auto fill

    Need to create a drop down list that will automatically fill in and change the code that is output.

    Example

    Drop down will contain:

    Site 1
    Site 2
    Site 3
    Site 4

    When Site 2 is selected, it will automatically change the web address in the code below:

    <a href="http://www.site2.com"><img src="http://www.bannerflux.com/userbanners/838-1-6-1273948252.png" border="0"></a>

    If Site 3 is selected from the drop down it will change the code to:

    <a href="http://www.site3.com"><img src="http://www.bannerflux.com/userbanners/838-1-6-1273948252.png" border="0"></a>

    Etc.

    Can someone point me in the right direction? Hope this isn't too confusing.

    Something like this but that will work through a database:
    http://dev.aol.com/accessibility/bes...ces/selectlist
    AllTopExchange - Banner Ad Network
    40,000+ Free Impressions When You Join.

    TrinityClicks Best GPT Site EVER! Join Now!

  2. #2
    SitePoint Wizard spence_noodle's Avatar
    Join Date
    Jan 2004
    Location
    uk, Leeds (area)
    Posts
    1,264
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    I'm not sure what your after but are after code for drop down menu for a form, then when an option is selected it will open a new window opening a website (or what ever, e.g. - a banner)?
    "Don't you just love it when you solve a programming bug only to create another."

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2010
    Location
    Netherlands
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This sounds more like a JavaScript thing. Try looking into onChange/onFocus events, they should be able to achieve what you're after.
    For example (not tested, may contain mistakes!):

    Code HTML4Strict:
    <select name="myBanner" onChange="javascript:changeCode(this.value)">
      <option value="1">Site 1</option>
      <option value="2">Site 2</option>
      <option value="3">Site 3</option>
    </select>

    You JS function should then look something like this:

    Code JavaScript:
    function changeCode(siteID) {
      switch(siteID) {
        case 1:
          document.getElementById('yourOutputElement').value = '<a href.....';
          break;
        case 2:
          document.getElementById('yourOutputElement').value = '<a href.....';
          break;
        default:
          // This will get executed if none of the above is selected
          document.getElementById('yourOutputElement').value = '<a href.....';
      }
    }


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
  •