473,326 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

JavaScript redirect and JSP submit

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.
Jul 23 '05 #1
2 11103
Omar wrote:
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
Jul 23 '05 #2
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!!
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Barnes | last post by:
Does anyone know of a good way to use the JavaScript string.replace() method in an ASP form? Here is the scenario: I have a form that cannot accept apostrophes. I want to use the replace() so...
4
by: john | last post by:
I have 2 major issues currently with javascript. 1. Doesnt anybody do any server side javascript anymore. I cant find anything on the net about it. My major issue is with database connections...
1
by: Ryann | last post by:
I hate javascript looking for help. I am trying to pass hidden fields around without showing a query string in the address bar. e.g. formA.asp not formA.asp?var1=blah&var2=blah I have...
4
by: fig000 | last post by:
Hi, I'm relatively new to Javascript so please bear with me on what might sound like silly questions. This is what I want to do: I'm working in classic asp (I have to for this project). I...
0
by: Michelle Keys | last post by:
I am trying to call a print function to print a string from a database using javascript. Which is RC_DATA of Varchar2(2500). This is a javascript is not being used. I have a thing that needs to...
2
by: dh | last post by:
How can a button that resides on the Main page tell the child Iframes to redirect without the page posting back? I keep getting a javascript error: "frames.iframe1 is null or not an object." I'm...
3
by: TJ | last post by:
Hi, I would like to ask something to user after user submits the form... I know I can ask user whehter they want to submit the form or not using client-script code such as onClick or onSubmit by...
12
by: KL | last post by:
Is there a way to redirect with javascript? I used javascript to do some validation on a form, but the form was set to redirect back to the index page after the submit button was clicked. So what...
2
by: Rahina | last post by:
I am working in Dreamweaver 8, and I have created a simple form: http://www.realmofmystery.com/app.html This is a free website I am doing for some friends, so nothing fancy. And, I learned web...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.