Karthik N Karthik N - 1 month ago 15
CSS Question

Pass variable to one page and find in the combobox

I am doing a HTML page with employee leave details. In that page, pending leave option having edit option. User may have edit that leave while its in PENDING. Once I click the edit button, the correspond row details will pass to update page. Leave type should be an combo box. So how to pass that combobox and make that variable as selected.

For example, When i click the edit button in Casual Leave category, the output should be

<select id="select_type">
<option value="Earned Leave">Earned Leave</option>
<option value="Casual Leave" selected>Casual Leave</option>
</select>


P.S: Need to pass the variable via javascript
So my javascript to pass the variable as below

function GetUrlValue(VarSearch){
var SearchString = window.location.search.substring(1);
var VariableArray = SearchString.split('&');
for(var i = 0; i < VariableArray.length; i++){
var KeyValuePair = VariableArray[i].split('=');
if(KeyValuePair[0] == VarSearch){
return KeyValuePair[1];
}
}
}
var x = decodeURIComponent(GetUrlValue('ReqType'));
var y = decodeURIComponent(GetUrlValue('FromDate'));
var z = decodeURIComponent(GetUrlValue('ToDate'));
var z1 = decodeURIComponent(GetUrlValue('NoDays'));


So pass the value to the combo box text and make it as selected. Hope you got my point.

Answer

You can make it like this, if you have the option value

var yourSelectedValue = somevalue;

$('#select_type option[value='+yourSelectedValue +']').attr('selected','selected');

Or like this

$("#select_type").val(yourSelectedValue );