469,326 Members | 1,463 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,326 developers. It's quick & easy.

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 59969
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
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.