JavaScript redirect and JSP submit

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Omar

    #1

    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='JavaS cript'>
    function valida()
    {
    var ok=true;
    var indexAccion = document.forms[0].accion.selecte dIndex;
    var indexTablas = document.forms[0].tablas.selecte dIndex;
    var indexBDatos = document.forms[0].BDatos.selecte dIndex;
    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.selected Index.value***>
    <select name="accion">
    <option value="inicio" selected>Selecc iona una opcion
    <option value="visualiz a.jsp">Visualiz ar registros de la tabla
    <option value="modifica .jsp">Modificar registros de la tabla
    </select>
    <select name="tablas">
    <option value="inicio" selected>Selecc iona una tabla
    <option value="tbl1">Ta bla 1
    <option value="tbl2">Ta bla 2
    </select>
    <select name="BDatos">
    <option value="inicio" selected>Selecc iona una base
    <option value="db1">Bas e 1
    <option value="db2">Bas e 2
    </select>
    <br><br><br>
    <input type="button" value="Aceptar" onclick='valida ()'>
    </form>

    Any ideas to figure it out?

    Regards,

    - Omar.
  • Mick White

    #2
    Re: JavaScript redirect and JSP submit

    Omar wrote:[color=blue]
    > 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='JavaS cript'>
    > function valida()
    > {
    > var ok=true;
    > var indexAccion = document.forms[0].accion.selecte dIndex;
    > var indexTablas = document.forms[0].tablas.selecte dIndex;
    > var indexBDatos = document.forms[0].BDatos.selecte dIndex;
    > 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.selected Index.value***>[/color]
    {snip]
    <script type='text/javascript'>
    function valida(form){
    with(form){
    if (!accion.select edIndex || !tablas.selecte dIndex ||
    !BDatos.selecte dIndex){
    alert("Elige un criterio");
    return false;
    }
    action=accion[accion.selected Index].value;
    return true;
    }
    }
    </script>

    .... // HTML stuff

    <form method='post' action="" onsubmit="retur n valida(this)">
    Mick

    Comment

    • Omar

      #3
      Re: JavaScript redirect and JSP submit

      Hi again,

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

      <script language='JavaS cript'>
      function valida()
      {
      var ok=true;
      var indexAccion = document.forms[0].accion.selecte dIndex;
      var indexTablas = document.forms[0].tablas.selecte dIndex;
      var indexBDatos = document.forms[0].BDatos.selecte dIndex;
      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(valueAcc ion)
      {
      case "visualiza.jsp" :
      window.location ="visualiza.jsp ?tablas=" + valueTablas + "&BDatos=" +
      valueBDatos;
      break;
      case "modifica.j sp":
      window.location ="modifica.jsp? tablas=" + valueTablas + "&BDatos=" +
      valueBDatos;
      break;
      case "inserta.js p": window.location ="inserta.jsp?t ablas="
      + valueTablas + "&BDatos=" + valueBDatos;
      break;
      case "elimina.js p": window.location ="elimina.jsp?t ablas="
      + valueTablas + "&BDatos=" + valueBDatos + ";
      break;
      } // switch
      } // if
      } // function
      </script>

      // ... HTML stuff

      <form>
      <select name="accion">
      <option value="inicio" selected>Select an option
      <option value="visualiz a.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">tb l1
      <option value="tbl2">tb l2
      </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!!

      Comment

      Working...