471,896 Members | 1,903 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,896 software developers and data experts.

How to use alert box inside a JSP


I am using JSPs in my application. The code goes like this-
Expand|Select|Wrap|Line Numbers
  1. <% 
  2. i=0;
  3. while(i<4) {
  4. %>
  5. <form name="Form" action="test.jsp">
  6. <table align="left" width="100%">
  7. <tr>
  8. <td>
  9. <% out.println("SNo");
  10. if(condition==true) {
  11. %>
  12. TRUE
  13. <% } else {
  14. %><input type="submit" name="name" value="Button" align="right"> 
  16. <script type="text/javascript">
  17. alert("Alert Box");
  18. </script>
  19. <% }
  20. %>
  21. </td>
  22. <td><%=i></td>
  23. </tr>
  24. </table>
  25. </form>
  26. <% }
  27. %>
My problem is - whenever the condition becomes false i'm getting the alert box. But when that alert box comes the contents that are on the jsp page are not getting displayed. Only after I click "OK" of alert box I'm able to see the contents.

I want to have an alert message box that appears on the page with the contents being seen.

Can anyone help me in solving this.

Thanks in advance
Dec 16 '08 #1
3 61122
11,448 Expert 8TB
Note that a JSP (which is just a piece of Java code in disguise that makes a Servlet) runs on a server. When it has finished its output (html text most of the time) is sent to the client (a browser most of the time) which renders the result. The browser also runs the (embedded) Javascript code.

When you have told the client to run a piece of Javascript somewhere in the middle of the (html) output, it will obediently do so.

kind regards,

Dec 16 '08 #2
392 Expert 256MB
Then do not call the alert() method in the middle of the page. If you want it to wait until the rest of the page has loaded, then do not call it before the rest of the page code.
Dec 16 '08 #3
Thanks a lot.
Now Im able to know my problem.
Im thinking of setting a session variable instead of alert() and after all the contents are displayed, I'll use alert() according to my requirement.
Dec 17 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

28 posts views Thread by Daniel | last post: by
1 post views Thread by L-and-F | last post: by
6 posts views Thread by bonehead | last post: by
4 posts views Thread by joe | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.