I am currently working on an HTML page that displays employee leave details. The page includes a pending leave option with the ability to edit. Users should be able to edit their leave while it is still marked as PENDING. Once the edit button is clicked, the corresponding row details will be sent to the update page. Additionally, I want the leave type to be displayed in a combo box and for the selected value to be highlighted.
For instance, if I click the edit button under Casual Leave category, the desired output would be:
<select id="select_type">
<option value="Earned Leave">Earned Leave</option>
<option value="Casual Leave" selected>Casual Leave</option>
</select>
P.S: It is essential to pass the variable through JavaScript. To achieve this, my JavaScript function to pass the variable looks like this:
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'));
To set the value of the combo box to the passed variable and highlight it as selected, please follow these steps. I hope this clarifies any confusion.