aspose file tools*
The moose likes JSP and the fly likes Diffterent action from different button Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Diffterent action from different button" Watch "Diffterent action from different button" New topic
Author

Diffterent action from different button

ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Hi all ,

I have a jsp page in my project that has 10 button & i want to perform different action from different button .

how can i do this . please provide some code .

Thanks ,
Kalai Selvan
Ranch Hand

Joined: Jul 07, 2004
Posts: 79
Hi rathi,
Can you please eloborate bit more on the problem. because for doing ten diff. things you can call ten diff. javascript functions on onclick of the buttons, or you can call a single function with ten different parameters.....
It all depends on your problem ..........

---------------
Kalai Selvan T.
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
One button will add 'name'( that user will enter ) in the database .
One button will delete 'name' from the database .
One button will add somthing in combobox as well as database also .

Like that .
I hope now it will be clear to u .
Thanks
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Plz any body post the answer .
Thanks
pradeep jaladi
Ranch Hand

Joined: Nov 21, 2004
Posts: 65
Hi,

I think ur using the yahoo mail id. ur Problem is like clicking the forward, reply, reply all, Send, Buttons .

So u can copy the javascript code and check the functionality and add it to ur code.

I think It works .
Or Simple assign a variable a value and in java script check for the variable and pass the parameter(URL) according to the request


Pradeep.Jaladi
Azz Romaysa
Ranch Hand

Joined: Dec 08, 2004
Posts: 66
You can do that with 2 methods. You make links or images(with links) in the place of buttons. like this for example



And you give each link an action. In the test.jsp you get the parametrs via <% String action = request.getParameter("action") %> then the following:

if ( action .equals("delete")){
..
..// delete code

}else if (action .equals("add")){
..
..
}

The second way to do this is to make for each button (action) a form. For example a form for the add action, en the action schould be action="test.jsp?action=add"

I hope this help you.

Azzeddine
Srinivas Krishna
Greenhorn

Joined: Dec 10, 2004
Posts: 8
Hi rathi,

i have a pattern soln for ur problem, so u try it out with the following code by changing variable with reference to ur application. so u r telling u have 10 buttons. so most probably u have to use this for 10 times or u can simplify by writing java script using some loops.

refer this code sample.




add the html statement in body of ur html code or form tag of u html code and

write the java script in head section of the html as given below


function validation()
{

//Flag for checking for Submiting the FORM for Saving or Not
var flgSub="0";

var ictr = 0;
var c1 = "";//variable for checking whether Check box checked or not.

for(ictr=0;ictr<(document.forms[0].elements.length)-1;ictr=ictr+1)
{
//Checkbox
c1=document.forms[0].elements[ictr].checked;
//alert("Chk box name = "+ document.forms[0].elements[ictr].name +" value = "+c1);
if (c1==true)
{
flgSub = "1";
}
}

if (flgSub=="1")
{
var confirmok = false;
confirmok = window.confirm("Do you want to send payslip throug E-mail?");
if (confirmok == true)
{
document.forms[0].method="post";
document.forms[0].target="";
document.forms[0].action="createallpdf.jsp";
document.forms[0].submit();
}


}
else
{
alert(" Sorry ! No Records Selected to submit");
}
}

try it with this .like this i have used for my problem and it as solve.

have a nice time
with regards


Srinivas Krishna
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Diffterent action from different button