I have a dropdown select menu where each option i get from php code, like this:
<div align = "center">
<p>
<select class="selectpicker" name="select_Parti[]" id="parti_list" multiple>
<?php
if($res_Participates){
while($tuplo = mysqli_fetch_array($res_Participates)){
$Nome_Parti = $tuplo["Nome"];
$Email_Parti = $tuplo["Email"];
?>
<option value = <?php echo $Nome_Parti . ", " . $Email_Parti?>><?php echo $Nome_Parti . ", " . $Email_Parti?></option>
<?php
}
}
?>
</select>
</p>
</div>
And i have a onchange function in another menu, that when it get's called i want to set the selected options by a given criteria. The problem is that i can't set any option selected from the called function. I've tried many ways, for example:
document.getElementById('parti_list').value = 'Joana Cunha, Joana@outlook.com';
I know that this question as been asked before, but none of the answers i found are working. Any suggestion?
Thanks
EDIT: Note that this question is different from mine.[Get selected value in dropdown list using JavaScript?
On my case i start with a dropdown menu that has no options selected and i'm not being able to, in a js script, set options to selected.
EDIT
So i found that the option is being selected as i wanted, but it only changes its state when i select another option. For example, if i do
document.getElementById("parti_list").options[1].selected = true;
on my onchange function, when it is called my option 1 doesn't change to selected, but if i manually open my dropdown menu and select for example option 0, both 0 and 1 appear selected. Any idea how to solve this? Maybe i'm missing some refresh function so that option 1 automatically changes to selected