Question:

In HTML tags, how do you make your <option>s go to different URLs?

by  |  earlier

0 LIKES UnLike

Pls. help...

In <form> tag, all your options lead to one URL which is the <action> attribute... How do you make each option go into different URLs? If it isn't really possible... do you have any suggestions?

 Tags:

   Report

2 ANSWERS


  1. I think this is what you&#039;re trying to do:

    &lt;form action=&quot;../&quot;&gt;

    &lt;select onchange=&quot;window.open( this.options [this.selectedIndex] .value, &#039;_top&#039;)&quot;&gt;

        &lt;option value=&quot;&quot;&gt; Choose a destination... &lt;/option&gt;

        &lt;option value=&quot;http://www.yahoo.com/&quot;&gt; YAHOO &lt;/option&gt;

        &lt;option value=&quot;http://www.google.com/&quot;&gt; GOOGLE &lt;/option&gt;

        &lt;option value=&quot;http://www.altavista.com/&quot;&gt; ALTAVISTA &lt;/option&gt;

        &lt;option value=&quot;http://www.amazon.com/&quot;&gt; AMAZON &lt;/option&gt;

        &lt;option value=&quot;http://artlung.com/&quot;&gt; ARTLUNG &lt;/option&gt;

    &lt;/select&gt;

    &lt;/form&gt;

    -----------------------------------

    remove spaces as necessary...

    Edit:

    -----------------------------

    Okay, let me break it down for ya. Here&#039;s what we have:

    onchange=&quot;window.open( this.options [this.selectedIndex] .value, &#039;_top&#039;)&quot;

    onchange - this means when the selection is changed do the following action / event...

    window.open(); - this is javascript method that opens a window. In this method we define 2 things: what URL to open, and any attributes associated with the window.

    this.options [this.selectedIndex].value - this line retrieves the value of the selected option in your select field.

    _top - defines how the window opens (an attribute)...another could be _blank or _new, etc..

    I hope this helps you better understand how this javascript works. =)


  2. If you want to do that you will have to use a little php.

    First (on your page:

    &lt;form action=&quot;somename.php&quot; method=&quot;post&quot;&gt;

    &lt;input name=&quot;sitename&quot; type=&quot;radio&quot; value=&quot;http://www.google.com&quot;&gt;www.google...

    (somename.php will only be a redirecting site)

    somename.php:

    &lt;html&gt;

    &lt;?php

    header( &#039;Location: $_POST[&quot;site&quot;]&#039; ) ;

    ?&gt;

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.
Unanswered Questions