473,386 Members | 1,795 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,386 software developers and data experts.

How to use alert box inside a JSP

14
Hi,

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"> 
  15.  
  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. %>
  28.  
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
tiijnar
Dec 16 '08 #1
3 61770
JosAH
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,

Jos
Dec 16 '08 #2
pronerd
392 Expert 256MB
@tiijnar
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
tiijnar
14
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

28
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()',...
1
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,...
6
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...
3
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...
4
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>
28
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) {
2
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...
2
by: sylver | last post by:
Hi, Following the discussion that can be found here:...
10
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...
1
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
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$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.