Get a free trial // Grow your CSS skills // Land your dream job

Dynamic Link via Select

  • # July 28, 2012 at 12:57 am

    I need for there to be a way for the user to select an option, from a form, obviously using the select and option elements in HTML, then dynamically changing the href of an anchor link. If there is a better way to do this, I am definitely open to any suggestions. I would prefer that it be done in PHP, however, like I said, I am also open to other languages.
    Thanks much!

    The links will also be to an external site, not the one I am working on.

    # July 28, 2012 at 4:19 am

    Like this?

    Or this:

     Go to here!

    # July 28, 2012 at 9:33 am

    I’d recommend not using inline javascript. Try something like:


    Then go with the Javascript by it self:


    Edit: Rewrote the code a bit.

    # July 28, 2012 at 10:58 am

    Thank you both a bunch, this works great, but is there any way I can do your way with multiple selects on the same page, without rewriting the code a bunch of times? I am not the greatest when it comes to JavaScript. Thanks again!

    Edit: they are all each in their own div also.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

There's a whole bunch of content on CSS-Tricks.

Search for Stuff   •   Browse the Archives

Get the Newsletter ... or get the RSS feed