So the code below works for this particular example, and I would like to make it work in scenario where the amount of forms select + input type is dynamic determined by user on previous page. So now we have in php array of $champion[] = ("Aatrox", "somethingelse", "somethingelse2"); so now we loop the amount of select and input fields. Every champion has different spells so now when you choose Q for first champion AAtrox in input you will see "Spell1" below in somethingelse input user might want to choose E and he will see the name of the spell for that champion in the input form
<?php 
    $champion = "Aatrox"
?>
    <select id="spell" name="spell" onchange="val()">
        <option value="Passive">Passive</option>
        <option value="Q" selected>Q</option>
        <option value="W">W</option>
        <option value="E">E</option>
        <option value="R">R</option>
    </select>
<input type="text" id="spellname" disabled>
<script>    
    var champions = {
        "Aatrox":["Passive", "spell1", "spell2", "spell3", "spell4"],
        "Ahri":["Passive", "spell1", "spell2", "spell3", "spell4"]
    };  
    function change(x){
        if(x==="Passive"){x=0;}
        if(x==="Q"){x=1;}
        if(x==="W"){x=2;}
        if(x==="E"){x=3;}
        if(x==="R"){x=4;}
        return x;
    }
    function val(d) {
        if(typeof d === "undefined"){
        d = document.getElementById("spell").value;}
        var spellname = document.getElementById("spellname");
        spellname.value=champions["<?php echo $champion; ?>"][change(d)];
    }
    val("Q");   
</script>
I can't really figure out dynamic how to check dynamic array from PHP in this javascript script
 
    