I'm new to this and don't really know how to ask the question. Forgive me if it's not clear at the outset, but I'll present my code to explain it to you.
On my page I have a drop-down list that displays (a <selector> that has the ID : list-category)
I also have search results that pop up. And at the bottom of his results I would like to display what is selected in the <selector>. For info the get_the_id() function is given by the CMS (WordPress) to display the right image, or the right title. I simply assumed that in order for it to display my text several times, I had to rely on that too.
<div class="listing-cat">
<i class="<?php echo $cat_icon; ?>"></i>
<span id="<?php echo get_the_ID()?>"></span>
<script type="text/javascript">
function update() {
var select = document.getElementById('list-category');
var option = select.options[select.selectedIndex];
document.getElementById('<?php echo get_the_ID()?>').innerHTML = option.text;
}
update();
</script>
</div>
After several tests I noticed that I only had the selected category displayed for the first search result and not for the others. I thought about it for a while and I said to myself, I'll use the unique ID of the post so that it will be correctly set up (reason why we see this PHP code)
Now nothing is displayed, but if I go into the source code of the web page, I can see that my PHP variables have the right ID of the post, I do not understand why it does not work:
<div class="listing-cat">
<i class=""></i>
<span id="69678"></span>
<script type="text/javascript">
function update() {
var select = document.getElementById('list-category');
var option = select.options[select.selectedIndex];
document.getElementById('69678').innerHTML = option.text;
}
update();
</script>
</div>
Do you have any leads to help me see what I might have missed? Do I need to make a loop?
<span>whenever the user changes the selected option in the<select>element?<select>element?