Arun
Arun

Reputation: 1482

Form Submit on dropdown change event Jquery

I have a form like this

<form method="get" id="searchform" name="search-page">

    <div class="rowElem">
        <input type="checkbox" name="category" id="" value="Appliances"  />
        <label>Appliances</label>
    </div>
    <div class="rowElem">
        <input type="checkbox" name="category" id="" value="Electronics and Computers"  />
        <label>Electronics and Computers</label>
    </div>
    <input type="submit" class="btn btn-primary sear htnew" name="analyse" value="Analyse" id="analyseSubmit" />

    <select name="chartType" id="chartName">
        <option value="1333" selected>Product Year</option>
        <option value="1334" >Category Year</option>
        <option value="1335" >Material Year</option>


    </select>

</form>

I need to submit the form when change the dropdown value.

i tried something like

$(function () {
        $("#chartName").change(function (e) {
            $('#searchform').submit();
        });

});

but it is not submitting .can any one help.Thanks in advance.

Upvotes: 0

Views: 1466

Answers (2)

AlexM
AlexM

Reputation: 479

You are missing an "action" on your form for the submit. I'm assuming you have some sort of handling for the form, so you need something like:

<form method="get" id="searchform" name="search-page" action="/go/to/success.html">

Upvotes: 0

Arun P Johny
Arun P Johny

Reputation: 388446

You are missing $ in front of the form selector, so the submit method is called on a string which is resulting in an error

$(function () {
    $("#chartName").change(function (e) {
        //missing $ here
        $('#searchform').submit();
    });
});

Upvotes: 3

Related Questions