[SalesForce] How to get selected value displayed in the drop-down using jQuery

I am using jQuery in Salesforce for a requirement where I could have Calendar (with drag & drop). When I click on a particular date, I get a pop-up, wherein I select couple of drop downs values, couple of text fields and save that record into an object. Now when I'm updating that record, I'm not getting the drop down values being displayed. However if I change the drop down to an input field, then the values are getting displayed.

var titleField = $dialogContent.find("select[name='title']").val(calEvent.title);
var doctorField = $dialogContent.find("input[id='doctorId']").val(calEvent.doctorId);

1st one is for drop-down and the 2nd one is for text field. The values get displayed when using the later one and not in the former one.

Please help me in this regard.

Best Answer

Are you trying to get the value from the drop-down, or set the value? Because, from what I see from your code, you are using .val(value) which is a setter method, rather than .val() which is a getter method.

I.e.

// Gets the value from the selected option in the <select name="title"> element
var titleField = $dialogContent.find("select[name='title']").val();


// Sets the selected option in the <select name="title"> element
var doctorId = '00Ab00000057v4B';
$dialogContent.find("select[name='title']").val(doctorId);