• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Passing Values.....

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My knowledge of JSP will be apparent here so there should be a easy answer. I have tried many different ways to do what I am asking:
How do I select a option value and within the next <FORM> check for that value and run statements depending on that value.
----
Factors.jsp
Form
...
Option
/Form
Form
...
If option = "xxx"
--Do this
...
/Form
____________________
Thanks in advance!
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try javascript!
 
Wayne Burr
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I didn't get in alot of detail with my initial problem and I appreciate the response.
I have two Form tags and on the Click event on the first form I trigger a Javascript funtion which in turn submits the form which I want to populate second form with data from the selected data depending on what was selected (If statements embedded in the second Form tag).
My problem right now is that when the first form is submitted and I have the parameter in the URL, my jsp calls does not return anything:
-----------------------------------
.
.
.
--Second form
String arg = request.getParameter("cmbFactor");

if (arg == "LAE_MONTHLY_EXPENSE") {
.
.
.
------------------------------
My URL has this displayed:
http://stfcorp148c:8080/ka/jsp/Factors.jsp?cmbFactor=LAE_MONTHLY_EXPENSE
I've also tried it as:
if (<%request.getParameter("cmbFactor");%> == "LAE_MONTHLY_EXPENSE") --and this also does not return anything
Any ideas?
Thanks!
 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wayne,
Can you try if (arg.equals("LAE_MONTHLY_EXPENSE"))
This should evaluate to true.
You can't expect the == to return true as it behaves differently. Details are a bit long to go into here.
HTH
Dinesh
[ December 07, 2002: Message edited by: Dinesh Kumar ]
 
Wayne Burr
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Having tried the following suggestion, I get the below error:
if (arg.equals("LAE_MONTHLY_EXPENSE")) {
Internal Servlet Error:
javax.servlet.ServletException
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:459)
Root cause:
java.lang.NullPointerException
at jsp._0002fjsp_0002fFactors_0002ejspFactors_jsp_83._jspService(_0002fjsp_0002fFactors_0002ejspFactors_jsp_83.java:262)
--------------
Everything that the I have researched points to the fact that what I am doing should work. I'm sure that I'm missing a simple element that is not screaming at me to add....
 
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looks like the value for "cmbFactor" is not available so you get NullPointerException when you try to reference "arg".
So you can take necessary measure(s) to avoid this. Simplest I can think of is switch the position i.e. if("someString".equals(arg)) ...)
and do some client side validation for to check if values are selected.
Bhushan
 
Wayne Burr
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I seem to be back where I started. What I want to accomplish is:
Select a option value from one <form> and pass that value to the second <form> to be evaluated to display data depending on what was selected in the first form.
The first <form> on a Onclick method that runs some JAVASCRIPT that stores the value in a varable, then submits the first <form>:
function frmFactorSelect_submit(i) {
if (i == 1) {
SelectedFactor = document.frmMaintFactor.cmbFactor.value;
document.frmMaintFactor.submit();
In the second <form> I am checking for the value "SelectedFactor":
<%
if (SelectedFactor) == "LAE_MONTHLY_EXPENSE")
{
for (int i=0;i<factorLMEList.getNumberOfFactorLME();i++)
{
nextfactor = factorLMEList.getFactorLMEs(i);
startdate = nextfactor.getstartDate();
enddate = nextfactor.getendDate();
orgunit = nextfactor.getorgUnit();
}
out.print("<OPTION selected value='" + 1 + "'>" + startdate + ", " + enddate + ", " + orgunit + "</OPTION>");
}
else
{
out.print ("<OPTION value='0'>It don't work</OPTION>");
}
-------
This is not working.
This can't be that of a difficult problem, but I have been working on it for a week and no solution as of yet.
Thanks in advance.
 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Wayne Burr:
[QB]if (SelectedFactor) == "LAE_MONTHLY_EXPENSE")
{
QB]


try this...
 
Wayne Burr
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the last suggestion:
if (new String("LAE_MONTHLY_EXPENSE").equalsIgnoreCase(request.getParameter("SelectedFactor"))){
Worked like a charm! Don't understand why the other solutions did not work, but progress has been made
Thanks to All!
 
Ranch Hand
Posts: 1170
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wayne, you have learned JSP but forgotten Java itself...

This is almost always NOT what you want.

The above is almost always what you do want. The first example checks to see if the object 'arg' is equal to the object "LAE_MONTHLY_EXPENSE" this may or may not be true depending on how the value got into arg.
Also, the equalsIgnoreCase() is good as is trim() to use but should not be necessary as you should be using a define (static final String) somewhere.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try this example :
test.jsp
<form name="f">
<select name="testselect" onChange="window.location='test.jsp?val='+document.f.testselect.value">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</form>

<%
String val= "";
if(request.getParameter("testselect") != null)
val = request.getParameter("testselect");
%>
// check for null before assigning values..good practice.. )

<form name="f2">
<input type="text" value="<%=val%>">
//the value of val will be printed in the text box of the second form
</form>

i hope this will solve ur problem
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic