elideli
elideli

Reputation: 179

jQuery - Change dropdown value and submit form

I have a page with a dropdown where the default value is Availability. I would like to change this value with jQuery to be Newest. The problem I'm having is it needs to do a postback where basically the page refresh to show content from the selected option. Any clue guys? I don't have to the source and neither the backend, all I'm able to do is manipulating with jQuery.

This what I have tried but it goes in an infinite loop, the page keeps reloading for ever.

$('select[name="ctl00$mainContentPlaceHolder$ListProducts$ListSort"]').val('CustomSortExpression').closest('form').submit();

Thanks

<select style="width:140px;" id="ctl00_mainContentPlaceHolder_ListProducts_ListSort" onchange="javascript:setTimeout('__doPostBack(\'ctl00$mainContentPlaceHolder$ListProducts$ListSort\',\'\')', 0)" name="ctl00$mainContentPlaceHolder$ListProducts$ListSort">
 <option value="CustomSortExpression">Newest</option>
 <option value="Availability">Availability</option>
 <option value="Alphabetical" selected="selected">Alphabetical (A-Z)</option>
 <option value="Brand">Brand Name (A-Z)</option>
 <option value="PriceHighestToLowest">Price (Highest to Lowest)</option>
 <option value="PriceLowestToHighest">Price (Lowest to Highest)</option>
 <option value="RecommendedProducts">Recommended</option>
</select>

Upvotes: 1

Views: 1300

Answers (1)

Exlord
Exlord

Reputation: 5371

var select = $('select[name="ctl00$mainContentPlaceHolder$ListProducts$ListSort"]')
if($(select).val() != 'CustomSortExpression')
   $(select).val('CustomSortExpression').closest('form').submit();

Upvotes: 1

Related Questions