Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Set a method when clicked on a hyperlink

 
Dee Gee
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All

In my application user needs to delete a few messages from time to time.
So the user will have a check box to select the messages and then a hyperlink "Delete the selected messages".

I have 2 problems here.
1)When the checkbox is clicked the textarea with the message should be disabled.
2)The hyperlink "Delete the selected messages" when clicked on should set a method DeleteMessage in class Messages. I am using a function setMethod which would set the particular method when a related button or link is cliked on. The code for the funciton is give below.

How do I achieve these two tasks. Please advice.

<script>
function setMethod(method){
alert(""+method);
document.forms[0].method.value=method;

}
</script>

Thank you,
Dee Gee
 
Chris Montgomery
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The disabling can be accomplished using JavaScript OnClick() event.

regarding the hyperlink item:
It looks like you are on the right track. You've created a field to hold the value of the method call. At the end of your java script, submit the form - document.forms[0].submit()

Then modify your action class to handle the method field.
<code>
if(myForm.getMethod() == "deleteSelectedMessages"){
myBusinessObject.DeleteSelectedMessagesMethod(myForm);
// then forward me somewhere or back to that same screen...

}
else{
// do other stuff
}
</code>

or however you want to do it...
 
Dee Gee
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Chris

Thank you.

I have another problem,
How do I call this method from an hyperlink?

Say "when I click on Delete selected messages I should be calling a method and not going to another page.
If the method executed successfully it would forward you to a new page.

Dee Gee.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic