Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I read param. value of automatically generated param names!

Status
Not open for further replies.

celia05es

Programmer
Jan 10, 2002
81
US
Hello,
I have a form and the parameter names are generated automatically... that is to say I don't really know the parameter names (Those are in fact attributes read from a list).
In the form I am building, the user can:
- modify only one parameter (submit goes to pp1.jsp). Each parameter has a submit button associated to it.
- modify all the parameter (submit goes to pp2.jsp)
In order to do this I use a javascript function called reDirect. if "0" is passed, the file is forwarded to pp1.jsp
if "1" is passed, the file is forwarded to pp2.jsp

My question is: When I submit the file to pp1.jsp (That is to say that the user only wants to modify only one specific parameter) How can I read the parameter name.....I can't do a getParameter(<param_name>) since I don't know the name!!!
Help me please!!

THank you


I generate the form the following way:
<form .... name="attributes" ...>
<table>
<tbody>
<tr>
<%
for (int i=1; i < ainfo1.length; i++)
{
name=ainfo1.getName();
value = mbsc.getAttribute(mbeanName1,ainfo1.getName();
%>
<td><%=name%>: </td>
<td><input type=text name=<%=name%> value=<%=value%>></td>
<td><input type="button" onClick="reDirect(0)" value="M"></td>
<%
}
%>
</td>
</tr>
<%
}
%>
</tbody>
</table>
<input type="button" onClick="reDirect(1)" value="All"> </form>



 
Hi,

User getParameterNames which will retrun you all the parameter names that are associdated with the request.

Alternative use JavaScript, Overload the reDirect method to accept an extra variable which is name and bind it to URL.

Ex:
Code:
 Enumeration enum = request.getParameterNames();
    while(enum.hasMoreElements()){
        String name = enum.nextElement().toString();
        String value = request.getParameter(name);
        // Button value in your jsp is M which you have to ignore
        if(!value.equals("M")){
           // is the value of name 
        }
    }

JavaScript Ex: where in the jsp you can use it as
String name = request.getParameter("param");
String fieldName = request.getParameter("name");

Code:
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>

<BODY>
<SCRIPT LANGUAGE="JavaScript">
<!--
function reDirect(intVal , fieldName){
  //
  if(intVal == 0){
		window.location="pp1.jsp?paramName=" + fieldName;
  }else if(intVal == 1){
		window.location="pp2.jsp";
  }
}
//-->
</SCRIPT>
</BODY>
<form .... name="attributes" ...>
<table>
<tbody>
<tr>
<%
for (int i=1; i < ainfo1.length; i++)
{
   name=ainfo1[i].getName();
   value = mbsc.getAttribute(mbeanName1,ainfo1[i].getName();
%>
 <td><%=name%>: </td>
 <td><input type=text name=<%=name%>  value=<%=value%>></td>
 <td><input type="button" onClick="reDirect(0,'<%=name%>')" value="M"></td>
<%
}
%>   
  </td>
  </tr>
<%
}
%>
</tbody>
</table>
<input type="button" onClick="reDirect(1,'')" value="All"> </form>
</HTML>

Hope this will help you

Cheers
Venu
 
Thank you very much.... it works perfectly!!!!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top