473,372 Members | 1,056 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 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 61761
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

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

Similar topics

by: Daniel | last post by:
Hello =) I have an object which contains a method that should execute every x ms. I can use setInterval inside the object construct like this - self.setInterval('ObjectName.methodName()',...
by: L-and-F | last post by:
www.lee-mcgeorge.co.uk I've been using custom Alert boxes for a long time in various guises. The way I've shown below is perhaps the easiest. There are more efficient and cleaner ways to do it,...
by: bonehead | last post by:
Greetings, I'm working on an e-mail form (btw many thanks to Philip Ronan for the very cool email address format tester function, best I've seen so far). I've been trying, with limited...
by: divya | last post by:
Hiii, Please read the following piece of code:- function SendToWebServer1(sendto) //sendto string contains a URL { if (document.form1.txtbookedby.value == "") { alert('your name field...
by: joe | last post by:
Hi, I defined: <div id="abc"> </div> in my .html file, after an Ajax query my weberserver sends: <script language="JavaScript"> alert('Hello World!"); </script>
by: Larax | last post by:
Best explanation of my question will be an example, look below at this simple function: function SetEventHandler(element) { // some operations on element element.onclick = function(event) {
by: Daz | last post by:
Hi everyone. Sorry for the confusing subject, I couldn't think how best to word it. What I would like to know, is if there is an equivilant to this code, in using JSON. <script...
by: sylver | last post by:
Hi, Following the discussion that can be found here:...
by: neverquit | last post by:
hi , Iam Nagesh,Begineer in using Ajax,well i have been using ajax in application, i have faced a problem while placing the responseTEXT into the <div> tag positioned inside the <form> tag iam...
by: bluer | last post by:
hi, i'm a newbie in java. I'm trying to trace a program in java and thought of using alert inside window.location, I would like to check what the si.getIdea_id_no() value is within the...
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.