Skip to content
Advertisement

Appending dropdown selection to url

I’m trying to append the dropdown selection to the url.

This selection part

    <div class="search2">
                <span>Adults</span><select id="adult" class="dropdown-select" name="selectdropdown">
                <option value="0">-</option>
                <option value="1">1</option>
                <option value="2">2</option>
                <option value="3">3</option>
                <option value="4">4</option>

</select>
</div>

Then the call sign

var Adult = $("#adult");

Final the append to url sign

url = url + "RedirectFromOutSide.aspx?arrivaldate=" + stringdata($("#StartDate").datepicker('getDate')) + "&departuredate=" + stringdata($("#EndDate").datepicker('getDate')) + "&hotelid=" + HotelID + "&Type=" + type + "&lang=" + Culture + "&adults=" + Adult;

But as the result comes &adults=object%... instead of &adults=1 or 2 or 3 or 4.

Advertisement

Answer

If you want to get the value:

$( "#adult").val();

However, if you want to get the selected text from drop-down:

$( "#adult option:selected" ).text();

Refer to this post: https://learn.jquery.com/using-jquery-core/faq/how-do-i-get-the-text-value-of-a-selected-option/

Advertisement