Select from drop-down list and open an iframe on the same page?

0

I need to open a frame within the same jsp page when selecting one of my options.

Principal.jsp

<script language="JavaScript">
function busqueda() {
location=document.buscar.lista.options[document.buscar.lista.selectedIndex].value;
}

</script>

    <h2><body></h2>
          
      <br><h1>Menu Principal</h1><br><br>
          <form name="buscar">
               <style type="text/css">
  h { text-align: center}
 </style>
<select name="lista" size="1">
<option value="Principal.jsp">Pagina Principal</option>
<option value="TablaPersonas.jsp">Consulta Personas</option>
<option value="TablaDirecciones.jsp">Consulta Direcciones</option>
<option value="TablaAutos.jsp">Consulta Automoviles</option>
          
</select>
                       
<input type="button" value="Aceptar" onClick="busqueda()">

</form> 

In this way, when selecting an option in the bottom by means of a frame, the selected page will be displayed.

I await your comments. Greetings!

    
asked by Angel Flores 14.05.2018 в 21:07
source

1 answer

0

If you do not misunderstand the question, what you could do is use .prop to change, or select the iframe you want.

For example, having 3 files, 1.html ; 2.html ; 3.html

You could do something like that;

HTML

<iframe src="1.html">
      <p>No Soportado.</p>
    </iframe>

    <select>
      <option value="1.html">Rojo</option>
      <option value="2.html">Verde</option>
      <option value="3.html">Azul</option>
    </select>

JavaScript / JQuery

$('select').on('change',function(){

    $('iframe').prop("src", $(this).val());

});

I hope it was what you needed, greetings!

    
answered by 14.05.2018 в 21:31