• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

controlling submit button in struts-2

 
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In a jsp ,I have a table with a few rows .The user need to select a row and click on 'Go' button placed below the table ,to go to next jsp.

If the user doesn't select a row and clicks 'Go' button, the user should be promped with a message saying "Please select a row to proceed!" and stay in the same page.

How to achieve this? On click of that button I tried calling a javascript function which has the alert for the above message but the control would go from view to Action class.

What should be done here to stay in same page?
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

On click of that button I tried calling a javascript function which has the alert for the above message


After the alert, return false from the javascript method. That's it, the page will not be submitted...
 
Pradeep Adibatla
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is what I wrote... I call this on button click



It still goes to next page!
 
Ankit Garg
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you see the second alert in your browser (alert("Add some vocabulary to proceed !!!");)?? And what is this

What's this statement supposed to do?? Where are you checking if any checkbox is checked??
 
Pradeep Adibatla
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I can see that alert statement!

Actually I don't have a checkbox rather user should select a row and then click on go button... The rows are added dynamically and hence to get the rowcount of the table I used that!

The 'if' condition was to check whether the user added any rows and selected (count>1) else it would be the table with only a header and hence the Alert!
 
Ankit Garg
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well returning false from a javascript method on the click event of a submit button stops the form processing. If it is not working, then change the submit button to a normal button. Then change the vocabCheck to something like this

Here formId is the value of the ID attribute of the associated form tag to be submitted. So if the user doesn't select a row, then the alert will be shown and nothing will happen, but if the user selects a row, then the form will be submitted...
 
Pradeep Adibatla
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That didn't work !

tried writing like this...



Unable to figure out the error! wonder how to trace it.
 
Ankit Garg
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Pradeep Adibatla wrote:That didn't work !


Did you try my code (the if-else one)?? There's no way it will not work. What you have to do is, change the submit button to a normal button, give the form an ID, and use the ID in the getElementById method in the else part...
 
Pradeep Adibatla
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Solved! returning false from a function doesn't hold good whereas return statement in a function call is a hit !!!



where reutnVal was the JS variable!
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ankit Garg wrote:Well returning false from a javascript method on the click event of a submit button stops the form processing. If it is not working, then change the submit button to a normal button. Then change the vocabCheck to something like this

Here formId is the value of the ID attribute of the associated form tag to be submitted. So if the user doesn't select a row, then the alert will be shown and nothing will happen, but if the user selects a row, then the form will be submitted...



Thank you. It worked for me
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic