I'm trying to get the Value or Text of my Select Options but for some reason all the methods I tried won't show me the ID of the Select. I think that because I'm executing the script before adding the Select in the DOM. Here is my code:-
JS file:
var myimgHTML2="" ;
var myString="";
myString +="<select id='sizesSelect'></select>";
myimgHTML2=myString;
return myimgHTML2;
JS (class) File:
$("#myrow").append(myHTML);
HTML File:
<body>
<div id="myrow" class="row">
<!-- Row Start -->
<!-- Row End -->
</div>
<table width="100%">
<tr>
<td colspan="2" align="center">
<a class="btn btn-primary btn-lg" id="back_btn" style="width:100px" align="center" onclick="stack_func()" href="#" role="button">Back</a>
</td>
<td colspan="2" align="center">
<a class="btn btn-success btn-lg" id="submit_btn" style="width:200px" align="center" role="button">Select This Theme</a>
</td>
</tr>
</table>
</div>
<script type="text/javascript">
document.getElementById('back_btn').style.display='none';
document.getElementById('submit_btn').style.display='none';
var myPMS = new PMS();
myPMS.sendToServer('path1_1');
var uniqueID=[];
uniqueID.push('path1');
function callToServer(id)
{
var res = id.split("_");
if (id=="path1")
{
document.getElementById('back_btn').style.display='none';
}
else if(res[0]=="themeId")
{
document.getElementById('submit_btn').style.display='block';
}
else
{
document.getElementById('back_btn').style.display='block';
document.getElementById('submit_btn').style.display='none';
}
uniqueID.push(id);
myPMS.sendToServer(id);
}
}
</script>
</body>
How I called for my Select ID (JS):
var selector = document.getElementById("sizesSelect");
var myvalue = selector[selector.selectedIndex].value;
console.log (myvalue);
and tried adding my ID like that with no result.
#sizesSelect
ALSO, I noted in this post that they have selectedIndex in the options while that didn't show for me in my Select options.