1
I would like to select <selected=true> on the basis of text and not in the value.
I tried that way:
function setSelectBoxByText(eid, etxt) {
    var eid = document.getElementById(eid);
    for (var i = 0; i < eid.options.length; ++i) {
        if (eid.options[i].text === etxt)
            eid.options[i].selected = true;
    }
}
Basically I have a Dropdownlist that when selecting sends the parameter to an IFRAME and this executes a query that returns me the keyword, with this keyword I want to leave another Dropdownlist The iframe returns:
<script type="text/javascript">parent.document.setSelectBoxByText('DDL_CategoriaMega','Casa');</script>
But it’s not working.
Page details Example: Page that calls the iframe
 <script type="text/javascript">
    function MudaDDLMega(valor) {
        document.getElementById('IFRAME_TESTE').src = "/busca_categoria_MEGA.aspx?IDCat=" + valor;
    }
 function setSelectBoxByText(eid, etxt) {
            alert('tste');
            var eid = document.getElementById(eid);
            for (var i = 0; i < eid.options.length; ++i) {
                if (eid.options[i].text === etxt)
                    eid.options[i].selected = true;
            }
        }
HTML
 <select id="DDL_Categoria" onchange="MudaDDLMega(this.value)">
    <option selected="selected" value="">Selecione</option>
    <option value="204">Academia de Escalada</option>
    <option value="228">Academias</option>
    <option value="1">Alugados</option>
Field I’d like you to change based on that first
 <select id="DDL_CategoriaMega">
    <option value="1">Apartamento</option>
    <option value="2">Casa</option>
    <option value="3">Casa em Condomínio</option>
    <option value="4">Chácara  Fazenda  Sítio</option>
    <option value="5">Flat</option>
</select>
						
Looking over the function
setSelectBoxByTextseems to be right... I imagine it has something to do with the iframe itself. When you executevar eid = document.getElementById(eid);, theeidis filled correctly? Try to give aconsole.log(or aalert, I don’t know), weeid.options[i].text. The options are correct?– Michael Siegwarth
is put an Alert('test'); and it does not appear, apparently this call via IFRAME is the problem.
– Dorathoto