php - (Fixed) Simple Select Value will not Populate via Jscript if the word is "House"

one text

I have a small Project website that I am learning to code with and in this website there is a Select Dropdown Menu of Music Genres

Here is a Video to help you visualise whats happening.

youtu.be/t4cJ7TCHiN8 (of the Problem)

And another video of how I can Paste "House" into the URL and get different MYSQL results

youtu.be/zf0S9WadQXo

I select a genre post the form and the reload shows me the results.

The value of the selected Option is then automatically selected by Jscript So the Search area and its Values remain the same as before.

I have Mainly used DocumentGetElementById or jQuery to Select the value, and I am echoing PHP variables into the DocumentGetElementById function.

There is no problems with 99.9% of the values and selectable genres, they all are automatically selected without any problems.

Just 1 Problem, The value "House" Will not select.

No matter how I try it just will not select. I have of course tried other methods, including jQuery and no matter how I alter my code or method of execution.

Nothing seems to make the value "House" populate.

Here is the code. And images to help visualise the problem.

Thank you for any help you may provide.

CODE.

<select id='genregrab' name='genre' class='menusmall'>
<optgroup label='Genre'>    
    <option value="">All Genres</option>
        <option value="EDM">EDM</option>
        <option value="DnB">DnB</option>
        <option value="Drum">Drum And Bass</option>
        <option value="Breakbeat">Breakbeat</option>
        <option value="Downtempo">Downtempo</option>
        <option value="Dance">Dance</option>
        <option value="Pop">Pop</option>
        <option value="Disco">Disco</option>
        <option value="Nu-Disco">Nu-Disco</option>
        <option value="House">House</option>            
        <option value="Hard">Hard House</option>
        <option value="Tech">Tech House</option>
        <option value="Techno">Techno</option>
        <option value="Deep">Deep House</option>    
        <option value="Future">Future House</option>
        <option value="Tribal">Tribal House</option>
        <option value="Tropical">Tropical House</option>
        <option value="Progressive">Progressive</option>
        <option value="Bass">Future Bass</option>
        <option value="Bounce">Future Bounce</option>
        <option value="Industrial">Industrial</option>  
        <option value="Electronic">Electronic</option>  
        <option value="Psychedelic">Psychedelic</option>
        <option value="Trance">Trance</option>
        <option value="Psy">Psy Trance</option>
        <option value="Minimal">Minimal</option>
        <option value="Ambient">Ambient</option>    
        <option value="Chillout">Chillout</option>  
        <option value="Synthwave">SynthWave</option>
        <option value="Retro">Retro</option>
        <option value="Hip">Hip-Hop</option>    
        <option value="Trip">Trip-Hop</option>
        <option value="Glitch">Glitch-Hop</option>
        <option value="Rap">Rap</option>    
        <option value="Afrobeat">AfroBeat</option>
        <option value="Grime">Grime</option>
        <option value="Trap">Trap</option>
        <option value="Trapstep">TrapStep</option>
        <option value="Dubstep">DubStep</option>
        <option value="Drumstep">DrumStep</option>
        <option value="Reggea">Reggea</option>
        <option value="RnB">RnB</option>
        <option value="Rock">Rock</option>
        <option value="Metal">Metal</option>
        <option value="Soul">Soul</option>                                                              
        <option value="Country">Country</option>
        <option value="Folk">Folk</option>                                                                  
        <option value="Jazz">Jazz</option>  
        <option value="Blues">Blues</option>
        <option value="Funk">Funk</option>  
        <option value="World">World</option>    
        <option value="Gospel">Gospel</option>  
        <option value="Latin">Latin</option>
        <option value="Ethnic">Ethnic</option>
        <option value="Bollywood">BollyWood</option>
        <option value="Moombahton">Moombahton</option>                                                              
        <option value="Orchestral">Orchestral</option>  
        <option value="Classic">Classical</option>  
        <option value="Cinematic">Cinematic</option>        
</optgroup>
</select>

Item Selected & POSTs Picked up By JScript to re-select the option

$(function(){

    var genre = document.getElementById('genregrab');
    
    var genredata = "<?php echo $genre ?>";

    genre.value=genredata;

});

(Of course i initially tried the following)

document.getElementById("genregrab").value="<?php echo $genre ?>";

However unlike the others , the word "House" will not be selected.

I think its to do with the word or something, as every other word will work fine.

Same process just selecting another genre, and it works fine

As you can see , the Trance genre was selected

Just the word "House" has the problem.

Selecting the genre House

And the Result after the Jscript

enter image description here

However , Select any other word and it works

As you can see in the image below

enter image description here

Any Ideas , Anybody?

I forgot to add the below code , from the GET and the MYSQL Results. Its possible the sanitizing is effecting the variables.

The GET

if (isset($_GET['genre'])) {
    $genre=$_GET['genre'];
    $genre = filter_var($genre, FILTER_SANITIZE_STRING);
    $genre = strip_tags($genre);
    $genre = str_replace(['"',"'"], "", $genre);
} else {$genre="";}

And the MYSQL variable - Which also gets posted to the URL for GET

$genre=$row['genre']; 
 $genre = str_replace(['"',"'"], "", $genre); 
  if ($genre == "null" | $genre==" "){$genre="";}
   $genresend = explode(',',trim($genre))[0];

(FIXED) - I copied the word House from where i scraped the Database and Pasted that word into this php IF and for whatever reason, Now my Value is Populated with the Word House.

Here is the Word from the Website

Hous?�

I am pretty sure it has some intrinsic value difference that can also be Copied and Pasted.

And here is the Small IF script that I used to Fix the problem

if ($genre =="Hous?�" | $genre=="House"){$genre="House";}

Very strange, and I am hoping somebody will have an answer as to why I have had to COPY & PASTE the word House from the website and then make an If Script so it can be changed.

Thank you for all your answers.

Source