I would like to select <selected=true>
based on text and not value .
I tried this 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 I select it sends the parameter to an IFRAME and it executes a query that returns me the key word, with that keyword I want to leave selected another DropDownList Iframe returns:
<script type="text/javascript">parent.document.setSelectBoxByText('DDL_CategoriaMega','Casa');</script>
But it is 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 you'd like to change based on this 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>