Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

on button click value is not getting

 
deep raj
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
value is not getting when i clicked on II and III buttons
code is like as



in b.jsp


please tell me what is the problem here
 
Chris Baron
Ranch Hand
Posts: 1061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess the form is submitted before the javascript finished. A submit button submits the form. That is what it is supposed to do.

Try onClick="return fun(this.id)" and return true in the function.
Alternatively you could change the input type to button and submit the form in the function with document.getElementById(n).form.submit().
 
deep raj
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
now when i click on first button it shows 0 on next page //correct value
but when i click II and III button it gives no value nothing would be printed
i not understand why?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64692
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please make sure that any code that you post is properly indented.
 
Michael Angstadt
Ranch Hand
Posts: 277
Eclipse IDE Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How many hidden input fields are created? In HTML, the value of the "id" attribute must be unique...
 
deep raj
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
actually i used hidden fields because i want
which button click
in a jsp page two buttons(submit) whose form action is same now i want which button is clicked
is there any other way except hidden field
tell me please
 
Michael Angstadt
Ranch Hand
Posts: 277
Eclipse IDE Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then all of your buttons should be in a single form and they should be type="button".
 
deep raj
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
after that?
 
Michael Angstadt
Ranch Hand
Posts: 277
Eclipse IDE Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
amrita singhal wrote:after that?

Then, because none of the buttons are "submit" buttons, you have to manually submit the form via Javascript as Chris described.

The problem you were having before was that you were creating three separate forms, each of which had a hidden field with the same ID. IDs are supposed to be unique, so when you were calling document.getElemenyById(), it was just returning the first element with that ID it could find. So, it would set the hidden field in the first form no matter what button you clicked. If you only have one form with one hidden field, then you won't run into this problem.



You could also just use buttons without a form and manually set the parameter if you don't have to use POST.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic