JavaScript redirect and JSP submit

O

Omar

Hi,

I've been trying to get the right way to send parameters to a JSP from
a HTML form. The referred JSP must get the values of the selects form,
because it executes queries and does stuff with that values. But the
only thing I've got it's a Tomcat error report.

The menu.jsp is something like this:

.... // HTML stuff
<script language='JavaScript'>
function valida()
{
var ok=true;
var indexAccion = document.forms[0].accion.selectedIndex;
var indexTablas = document.forms[0].tablas.selectedIndex;
var indexBDatos = document.forms[0].BDatos.selectedIndex;
if (indexAccion==0 || indexTablas==0 || indexBDatos==0)
{
alert("Elige un criterio");
ok=false;
}
if (ok)
document.forms[0].submit();
window.location.href =
document.forms[0].accion.options[indexAccion].value;
}
</script>

.... // HTML stuff

<form method='post' ***SHOULD BE THE accion.selectedIndex.value***>
<select name="accion">
<option value="inicio" selected>Selecciona una opcion
<option value="visualiza.jsp">Visualizar registros de la tabla
<option value="modifica.jsp">Modificar registros de la tabla
</select>
<select name="tablas">
<option value="inicio" selected>Selecciona una tabla
<option value="tbl1">Tabla 1
<option value="tbl2">Tabla 2
</select>
<select name="BDatos">
<option value="inicio" selected>Selecciona una base
<option value="db1">Base 1
<option value="db2">Base 2
</select>
<br><br><br>
<input type="button" value="Aceptar" onclick='valida()'>
</form>

Any ideas to figure it out?

Regards,

- Omar.
 
M

Mick White

Omar said:
Hi,

I've been trying to get the right way to send parameters to a JSP from
a HTML form. The referred JSP must get the values of the selects form,
because it executes queries and does stuff with that values. But the
only thing I've got it's a Tomcat error report.

The menu.jsp is something like this:

... // HTML stuff
<script language='JavaScript'>
function valida()
{
var ok=true;
var indexAccion = document.forms[0].accion.selectedIndex;
var indexTablas = document.forms[0].tablas.selectedIndex;
var indexBDatos = document.forms[0].BDatos.selectedIndex;
if (indexAccion==0 || indexTablas==0 || indexBDatos==0)
{
alert("Elige un criterio");
ok=false;
}
if (ok)
document.forms[0].submit();
window.location.href =
document.forms[0].accion.options[indexAccion].value;
}
</script>

... // HTML stuff

<form method='post' ***SHOULD BE THE accion.selectedIndex.value***>
{snip]
<script type='text/javascript'>
function valida(form){
with(form){
if (!accion.selectedIndex || !tablas.selectedIndex ||
!BDatos.selectedIndex){
alert("Elige un criterio");
return false;
}
action=accion[accion.selectedIndex].value;
return true;
}
}
</script>

.... // HTML stuff

<form method='post' action="" onsubmit="return valida(this)">
Mick
 
O

Omar

Hi again,

I've been working and so far I got this:

<script language='JavaScript'>
function valida()
{
var ok=true;
var indexAccion = document.forms[0].accion.selectedIndex;
var indexTablas = document.forms[0].tablas.selectedIndex;
var indexBDatos = document.forms[0].BDatos.selectedIndex;
var valueAccion =
document.forms[0].accion.options[indexAccion].value;
var valueTablas =
document.forms[0].tablas.options[indexTablas].value;
var valueBDatos =
document.forms[0].BDatos.options[indexBDatos].value;
if (indexAccion==0 || indexTablas==0 || indexBDatos==0)
{
alert("Elige un criterio");
ok=false;
} // if
if (ok)
{
switch(valueAccion)
{
case "visualiza.jsp":
window.location="visualiza.jsp?tablas=" + valueTablas + "&BDatos=" +
valueBDatos;
break;
case "modifica.jsp":
window.location="modifica.jsp?tablas=" + valueTablas + "&BDatos=" +
valueBDatos;
break;
case "inserta.jsp": window.location="inserta.jsp?tablas="
+ valueTablas + "&BDatos=" + valueBDatos;
break;
case "elimina.jsp": window.location="elimina.jsp?tablas="
+ valueTablas + "&BDatos=" + valueBDatos + ";
break;
} // switch
} // if
} // function
</script>

// ... HTML stuff

<form>
<select name="accion">
<option value="inicio" selected>Select an option
<option value="visualiza.jsp">Select records from table
<option value="modifica.jsp">Update records from table
<option value="inserta.jsp">Insert records into table
<option value="elimina.jsp">Delete records from table
</select>
<select name="tablas">
<option value="inicio" selected>Select a Table
<option value="tbl1">tbl1
<option value="tbl2">tbl2
</select>
<select name="BDatos">
<option value="inicio" selected>Select a DataBase
<option value="db1">db1
<option value="db2">db2
</select>
<br><br><br>
<input type="button" value="Aceptar" onclick='valida()'>
</form>

// ... HTML stuff

It still doesn't work, but I think is a better approach. Anyway, if
you could give me a hand I'd appreciate it!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top