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

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 61761
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...
1
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...
0
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...
0
isladogs
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.