Compose a link based on the option value of select

advertisements

I have 2 dropdown menus, and I need to compose a link with it's values.

Here is the code:

<form id="dropdown1">
    <select id="linha">
        <option value="G12">Option 1</option>
        <option value="G11">Option 2</option>
        <option value="H89">Option 3</option>
    </select>
    <select id="dia">
        <option value="all">Every day</option>
        <option value="work">working days</option>
        <option value="sat">saturday</option>
        <option value="sun">sunday</option>
    </select>
</form>

I need something in JavaScript to "compose" a link with http://somewebsite.com/*selected_linha_value*/*selected_dia_value*

How can I do that?


Take a look at: http://jsfiddle.net/ERHhA/

You can use jQuery val() to get the value of the select boxes. Then just append these values to the base url.

var url = "http://somewebsite.com/" + $('#linha').val() + "/" + $('#dia').val();