• Post Reply Bookmark Topic Watch Topic
  • New Topic

Calling js function from jsp based on validaiton  RSS feed

 
sudheshna Iyer
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hava a form for entering member number. When user enters membernumber and selects "Go" system should retrieve customer information. Customer information includes fname, lname,.. states (states customer lived in).

My requirment is that if no states exist for the customer, I should display an alert msg to user saying no states exist.

How can achieve this? How can I call javascript function to display msg from jsp, after checking whether states obj is empty, from jsp.

I have seen on thread on this topic, but I didn't get clear answer from that.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66304
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please do not cross-post the same question in multiple forums. It wastes people's time when multiple redundant conversations take place. Please read this for more information.

I have closed your other redundant post.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66304
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JSP code and the JavaScript code are completely independent.

The JSP code runs on the server in order to format the page to send to the browser. Once the response is sent, the page is an HTML page just like any other. The fact that it was generated by a JSP is irrelevant.

Only after the page is loaded by the browser does any JavaScript execute.

Please see this article to understand how JSPs work.
 
sudheshna Iyer
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your reply. Then can you please suggest how I can fulfill my requirements.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66304
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you need to contact the server for information after a client-side action, you either need to submit the page and reconstruct it with the new data (rather old-fashioned, at this point) or use Ajax to retrieve the data.
 
sudheshna Iyer
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, I am reconstructing the form data with customer information after form submission from servlet. But customer object has list of states. If the states list is empty then I should alert msg to user. Would this be possible?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66304
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An alert? That's JavaScript (and a terrible way to communicate).

Or do you want a message to appear on the page? The latter is easy to handle with conditional JSP code.
 
sudheshna Iyer
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I know it is easy display as a message on the screen. But my requirement is to show up an alert message which requires javascript!
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://letmegooglethatforyou.com/?q=JavaScript+alert

What do you not understand about an alert? What have you tried?

Eric
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!