Hi all.Am new to this forum so cut me some slack if I don't articulate my problem with utmost clarity.My problem is that I have a javascript function such as:

function modReg(x,y)
{
 <!--

        var answer = confirm ("Do you really want to deregister user" +x+"?")
        if (answer)
            {
            document.leo["id"].value=x;
            document.leo["two"].value=y;
            document.leo["type"].value = "deregister";
            document.leo.submit();
            }
        else
            alert ("No action was taken.")

        // -->
}

Now, leo is a hidden form with the 2 fields namely "id and "two".Viewing source, I see that the parameters I need are well acquired by the function.In next page, I haven't been successful at retrieving the passed parameters. Please assist?

Ensure that those fields are within the form tags on the page you are submitting

Hi Thirusha and thanks.
Now here is the way I did the page as concerning the javascript function.First i had the function above at top part of the page then later had this form :

<form name="leo" id="leo" method="post" action="edituser.html">
<input type="hidden" name="id" value="" />
<input type="hidden" name="two" value="" />
</form>

Down the page I have a button :

<input type="button" name="deregister" value="deregister" onclick=return modReg("25","35")>

Again after opening my page and clickikng on the button, when i view page source I see that the two values have in deed been picked but on trying to access them from the next pagei.e.
request.getParameter().....i am not able to get the two.
Now I hope this is much clearer....Please advice!

I see you are posting to a html page. request.getParameter will only work server side, that is not on a html page but rather on a jsp page.

Yeah..it's a .jsp file ...so how do you retrieve the two passed parameters in the case that they're being picked up well on the first page?.....Anyone please assist !!!....Or is this question for JSP Forum?.................I hope one of you will duly assist......Thanks a lot in advance!

It should work if the form is posting correctly, can u post the code of both the pages, and I can take a look.

Thank you so much Thirusha.Below is code for my users.jsp passing the one parameter which is username, and is successfully retrieved in the next page edituser.jsp using request.getParameter("id");

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%@ page language="java" import="java.sql.*" %>
<jsp:useBean id="viewbeanId" scope="session" class="viewbean.generate" />
<jsp:setProperty name="viewbeanId" property="*" />
<%
String powerful = (String)session.getAttribute("powerful");
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><!-- InstanceBegin template="/Templates/index.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
    <script language="javascript" type="text/javascript">
     function modRegistration(x)
    {
        <!--

        var answer = confirm ("Do you really want to edit user " +x+"?")
        if (answer)
            {
            document.leo["id"].value = x;
            document.leo["type"].value = "deregister";
            document.leo.submit();
            }
        else
            alert ("No action was taken.")

        // -->
    }
    </script>
<!-- InstanceBeginEditable name="doctitle" -->
<title>hello</title>
<!-- InstanceEndEditable -->
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<link href="style.css" rel="stylesheet" type="text/css">
<!-- InstanceBeginEditable name="head" -->
<style type="text/css">
<!--
.style2
{
    font-size: 30px;
    color: #92bbeb;
}
.style3 {font-size: 18px}
.style4 {font-size: 32px}
-->
</style>
<!-- InstanceEndEditable -->
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

            <form id="leo" name="leo" method="post" action="edituser.jsp">
            <input type="hidden" name="id" value="">
            <input type="hidden" name="type" value="">
            </form>

<table width="1000" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td><img src="images/header.jpg" alt="" width="100%" height="182" border="0"></td>
  </tr>
  <tr>
    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="6">&nbsp;</td>
        <td width="230"><table width="76%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td><a href="home.jsp"><img src="images/home.jpg" alt="" width="230" height="55" border="0"></a></td>
          </tr>
          <tr>
            <td><a href="#"><img src="images/products.jpg" alt="" width="230" height="40" border="0"></a></td>
          </tr>
          <tr>
            <td><a href="trailer.jsp"><img src="images/sms.jpg" alt="" width="230" height="40" border="0"></a></td>
          </tr>
          <tr>
            <td><a href="stolen.jsp"><img src="images/Buyers.jpg" alt="" width="230" height="40" border="0"></a></td>
          </tr><%
if(powerful.equals("yes"))
    {
%>
          <tr>
            <td><a href="inputuser.jsp"><img src="images/Admin.jpg" alt="" width="230" height="40" border="0"></a></td>
          </tr>
<%
    }
%>
          <tr>
            <td><a href="#"><img src="images/agents.jpg" alt="" width="230" height="40" border="0"></a></td>
          </tr>
          <tr>
            <td><a href="#"><img src="images/customers.jpg" alt="" width="230" height="62" border="0"></a></td>
          </tr>
        </table></td>
        <td width="764" "><!-- InstanceBeginEditable name="EditRegion3" -->
<!--<div align="left" style="width: 590px; height: 300px; overflow: scroll; border: 2px solid black; background-color: #ccc;"> -->

                 <!--<h2><font color="#92BBEB">PRODUCTS</font></h2><br>-->
<%
String [] previmei;
int cols = 0;
int rows = 0;

Statement stmt = null;
ResultSet rst = null;
ResultSetMetaData meta = null;

   Connection con = viewbeanId.getConnection();

   rst = null;
   stmt = null;
stmt = con.createStatement();
   rst = stmt.executeQuery("SELECT username,password FROM tUSERS");
    meta = rst.getMetaData();
   cols = meta.getColumnCount();
   rst.last();
   rows = rst.getRow();
previmei = new String [rows];

%>
<center>
    <div align="top" style="height:275px;overflow:auto;border-color:#0000FF; color:aqua; font-size:medium;">

        <table width="100% "border="0" cellspacing="1" cellpadding="0" bgcolor="#252F3C" >
    <tr>
        <td colspan="5"><center><font size="5" color="#FFFFFF">Deregister Users</font></center></td>
    </tr>
    <tr>
<%
   for(int i=1;i<(cols+1);i++)
       {
       %>
       <td><b><%out.print(meta.getColumnName(i));%></b></td>
        <%
       }
rows = 0;
            rst.beforeFirst();
        while(rst.next())

        {
           previmei[rows] = rst.getString("username");

%>
<td></td>
</tr>
            <tr>
            <td><%= previmei[rows]+" "%></td>
            <td><%=rst.getString("password")%></td>
<%      if(powerful.equals("yes"))
        {
%>
            <td>
<%
    out.println("<input type='button' value='deregister' onClick=\"return modRegistration('" + previmei[rows] + "')\">");

%>
            </td>
<%
        }
%>
            </tr>
<%
        rows++;
    }
%>
 <!--</div>-->
 </table>

</div>
</center>

 <!-- InstanceEndEditable --></td>
      </tr>
    </table></td>
  </tr>
</table>
<table width="1000" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td><table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#252F3C">
      <tr>
        <td width="237" valign="top" bgcolor="#252F3C">&nbsp;</td>
        <td width="763" valign="top">&nbsp;</td>
      </tr>
    </table></td>
  </tr>
</table>
<table width="1000" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td><table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#252F3C">
      <tr>
        <td width="237" height="100" bgcolor="#252F3C">&nbsp;</td>
        <td width="763"><table width="100%" border="0" cellspacing="15" cellpadding="0">
          <tr>
            <td width="36%" align="center"><a  </td>
          </tr>
        </table></td>
      </tr>
    </table></td>
  </tr>
</table>

</body>
<!-- InstanceEnd --></html>

My main question is how to pass both username and password at the javascript function such as
function modRegistration(username,password){} and then how to retrieve the two in the page posted to?as per now, I have no clue.......Please assist

Adding the username and password to the javascript function is easy, just send those two values to the function itself, and ensure that the function accepts two inputs.

I dont see anywhere in your code where u are using request.getParameter("id") ??

I wouldnt send in the username and password in the javascript function unless you are going to need them for some purpose, not the purpose of posting them to the next page only, in the function.

You dont need to place comment out the javascript in the script tags anymore. Also it is better practice to use a servlet to connect to the database then doing it through a jsp.

I cant see any reason why the information is not getting posted to the next page.

Thank you so much Thirusha for your good counsel.Just help me with this:If i had a js function such as the one below in first jsp

<script language="javascript" type="text/javascript">
function modRegistration(x,y)
{
<!--

var answer = confirm ("Do you really want to edit user " +x+"?")
if (answer)
{
document.leo["id"].value = x;
document.leo["two"].value = y;
document.leo["type"].value = "deregister";
document.leo.submit();
}
else
alert ("No action was taken.")

// -->
}
</script>

how do i use request.getParameter("id","two");
or another to retrieve the two posted items in the target jsp?.....Thank you so much!

<%String sID = request.getParameter("id");%>

Use the same code for the other parameters, remember to change the name of the String though.

Thanks a lot Thirusha.That was the thing I needed...it works.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.