chase cabrera chase cabrera - 1 year ago 90
Javascript Question

Change selected value in dropdown list if session variable exists

I've got an html table of attendees with a drop down at the top with three values which filters out VIP, general or show all. This works perfectly, my issue is when a user clicks on a record in the table they going to a modal and after closing the modal the page is refreshed.

I stored a cookie variable and selected the value when the drop down is draw but applying because it's looking for a change evente. How can I change the drop down with javascript after the window has loaded?

<select id="ea_constrain" name="ea_constrain" class="blackM" style="width:100px;height:20px;">
<option value="0">Show All</option>
<option value="1" >Attending</option>
<option value="2">VIP</option>


$( document ).ready(function() {

$("select#ea_constrain option").filter(function() {

return $(this).val() == <cfoutput>"#cookie.attendeeconstraint#"</cfoutput>;
}).prop('selected', true);


Thank you in advanced!

Answer Source

Two ways (jQuery):

Page load

 //code here after page load

Event trigger

$('.dropdown').bind('change', function(){
 //code to trigger event
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download