aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes on button click value is not getting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "on button click value is not getting " Watch "on button click value is not getting " New topic
Author

on button click value is not getting

deep raj
Ranch Hand

Joined: Dec 11, 2009
Posts: 186
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

Joined: Mar 21, 2003
Posts: 1049
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

Joined: Dec 11, 2009
Posts: 186
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

Joined: Jan 10, 2002
Posts: 61233
    
  66

Please make sure that any code that you post is properly indented.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Michael Angstadt
Ranch Hand

Joined: Jun 17, 2009
Posts: 273

How many hidden input fields are created? In HTML, the value of the "id" attribute must be unique...
deep raj
Ranch Hand

Joined: Dec 11, 2009
Posts: 186
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

Joined: Jun 17, 2009
Posts: 273

Then all of your buttons should be in a single form and they should be type="button".
deep raj
Ranch Hand

Joined: Dec 11, 2009
Posts: 186
after that?
Michael Angstadt
Ranch Hand

Joined: Jun 17, 2009
Posts: 273

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.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: on button click value is not getting