Jsp combo box

I'm having trouble with a jsp search page in which I have 2 combo boxes and one submit button.
Both combo boxes retrieve data from an access db.
The problem is how to specify from which combo the request is sent.
I tried this piece of code but it didnt work:

if (request.getParameter("combo1") != null) {
execute this code;

} else if (request.getParameter("combo2") != null) {
execute that code;
}

Thanks for your help.
dtaifourAsked:
Who is Participating?
 
moduloCommented:
PAQed, with points refunded (50)

modulo
Community Support Moderator
0
 
rajaamirapuCommented:
Add a entry -1 as the first entry in both the combo boxes.Then you will know which entry is selected
0
 
dtaifourAuthor Commented:
Thanks but I dont see what you mean clearly ...... could you plz right on the code ?
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
Ryan ChongCommented:
The if condition looks ok for me, what if you try to output the parameter combo1 and comb2?

Example:

System.out.println("combo1 = " + request.getParameter("combo1"));
System.out.println("combo2 = " + request.getParameter("combo2"));

And if needed, you can post your jsp scripts here.

regards
0
 
rajaamirapuCommented:
Add like this
 <select size="1" name="combo1">
    <option value="-1"></option>
    <option value="34">34</option>

    <select size="1" name="combo2">
    <option value="-1"></option>
    <option value="34">34</option>

0
 
rajaamirapuCommented:
I am mentioning about this
<option value="-1"></option>
0
 
dtaifourAuthor Commented:
The problem is not about knowing which entry is selected but rather which combo is selected.
Therefore, it excutes both codes and display all the html that comes with both combos.
0
 
dtaifourAuthor Commented:
hi,
I have finally found the solution, the code goes like this:

if ((request.getParameter("NameCombo") != null) && (request.getParameter("DeptCombo").equals("Select by Department"))) {
execute this code;
}

if ((request.getParameter("DeptCombo") != null) && (request.getParameter("NameCombo").equals("Select by Name"))){
execute that code;
}
the problem was to get the parameter sent by the combo that was not selected.
Anyway thanks for your comments.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.