mamasi
mamasi

Reputation: 915

How can I after changing selected value in my form call url with GET value?

How can I after changing selected value in my form call url with GET value:

For example: I selected <option value="dog">Dog</option> and this url is running:

www.mysite.com?query=dog

<form>
    <select class="select-box">
        <option name="query" value="dog">Dog</option>
        <option name="query" value="cat">Cat</option>
        <option name="query" value="pig">Pig</option>
    </select>
</form>

Upvotes: 0

Views: 50

Answers (2)

vikrant singh
vikrant singh

Reputation: 2111

$(document).ready(function(){
$(".select-box").change(function () {
    $.ajax({
        url: "www.mysite.com"
        type: 'get', //a http get request
        data: {
            query: $(this).find("option:selected").val()
        }
        success: function (response) {
            alert(response); //handle response here
        }
    });
});
});

Upvotes: 1

artm
artm

Reputation: 8584

$(".select-box").on("change", function() {
    var query = $('.select-box').find(":selected").text();
    $.ajax( ... pass in url and 
        data: {query : query}
    )
}

Upvotes: 1

Related Questions