Link to home
Start Free TrialLog in
Avatar of prain
prainFlag for United States of America

asked on

How to trap a button click?

Hello,

Here is the scenerio....

I have two buttons showing on browser. Both buttons are linked to the same Servlet.

How do I trap which one was clicked by the user WITHIN  THE doPost() method?

Thanks
prain
Avatar of fargo
fargo

Hi,

One way is to use a hidden parameter to see which button is click.

You can set the value of the hidden parameter depends upon which button is clicked.

fargo
ASKER CERTIFIED SOLUTION
Avatar of bloodredsun
bloodredsun
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi,

<script>
 
function update(valuetoset){
document.forms[0].hiddenparamname.value=valuetoset;
document.forms[0].submit();
}

</script>

<html:button.......onclick="update('button1value');"/>

<html:button.......onclick="update('button2value');"/>

fargo
Avatar of prain

ASKER

bloodredsun,

I like your method. But when I implemented that in my source, I am getting the famous HTTP error 404. It does not recognise the .do part?

Here is a portion of my code...

out.println("<form method=\"post\" action=\"/pSystem/PFolders.do?src=show\">");
.....
....
out.println("<form method=\"post\" action=\"/pSystem/PFolders.do?src=add\">");


and then in my doPost() I have a block like this....

if("show".equals( request.getParameter("show") ) ){
  System.out.println("coming from show");
}else{
System.out.println("coming from add");
}

And the error is
HTTP Status 404 - /pSystem/PFolders.do

--------------------------------------------------------------------------------

type Status report

message /pSystem/PFolders.do

description The requested resource (/pSystem/PFolders.do) is not available.


Note : I have a PFolders.class file in the appropriate folder in the WEB-INF and is a working Servlet and
I have been working with that for a while now. Only thing I added was the .do  as you have specified.

Any input will be appreciated.

Thanks
prain
Avatar of prain

ASKER

OK. Blood,

I think I fixed that problem.

But now I have another problem. When any of the two buttons is clicked,
it always goes to "Coming from add".

Trying to figure out.

-prain
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of prain

ASKER

Bloodredsun,

Thanks pretty clever.

I will split the points b/w blood and fargo, but majority goes to Blood.

Thanks fargo too.
cheers prain