Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to find which button is clicked  RSS feed

 
Naveen bpl
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a problem to recognize which is clicked. I am not whether this posting should go to html or jsp. I am sorry if I am posting it in the wrong place.

My problem is I have something like this:

for(int j = 0; j < 20; j++)
{
<input type="button" name='<%= "Select" + j %>' value="Select" size="10"
onKlick="callSubmit()" />
}

<script language="JavaScript">
function callSubmit()
{
document.forms[0].submit();
}
</script>

I am using Struts.. so in my action class I have this

HttpSession session = request.getSession();
String select0= (String) request.getParameter("Select0");
String select1= (String) request.getParameter("Select0");
...


if(select0 != null)
System.out.println("Select0 is Selected");
else
System.out.println("Select0 is null");

if(select1 != null)
System.out.println("Select1 is Selected");
else
System.out.println("Select1 is null");

....

But it's always printing null irrespective of which button is clicked.

So please help me out in how find which button is clicked if all the buttons have the same value...


Thanks,
Naveen
 
Kerry Wilson
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would be much better practice to have all the names the same, but the value should be variable. Since you are submitting via javascript the browser will not send the button. Rather, you should do this:



That should fix you up.
 
Naveen bpl
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!