Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

alert function

 
chinna kumar
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
i need to pass a variable to alert function,i tried many ways,but i cud not get the result.

this is my code..

<%
String MSISDN=(String) application.getAttribute("Msisdn");
String IMSI=(String) application.getAttribute("Imsi");
String SIM=(String) application.getAttribute("Sim");
%>

<script language="javascript">
function one()
{
alert("value of"+MSISDN+" is"+MSISDN);
}

please advise me on this
 
Niki Nono
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


in the above code only one of them work.
try out each and you will come across the correct one.
i dont remember the exact one and i dont have a webserver nearby.sorry
try it out and let me know.

[ April 19, 2005: Message edited by: Niki Nono ]
[ April 19, 2005: Message edited by: Niki Nono ]
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
repeat after me, and write it down 10.000 times (Bear will check your homework for spelling errors):
JSP runs on the SERVER, Javascrip runs on the CLIENT. You can NOT call Javascript from JSP nor can you call JSP from Javascript.
 
Sarath Mohan
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can NOT call Javascript from JSP nor can you call JSP from Javascript.


Sure???!!!

You are wrong!!! JSP is nothing but a combination Java Code+Java Script+Html Tags.

So we can call java script function in JSP and java script can access java variables declared in jsp.

Cheers
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSP is not a combination of those things.
JSP is a server side platform that writes text to an output stream.

Within that stream, you CAN include HTML and Javascript code.
When this code makes it to the browser it will be interpreted and or run.
By the time this happens, the JSP processing will be over and finished and completed and done. If you want to interact with the server again, you will need to POST a new form to the server so the whole process can start again.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll try to illustrate that point.
Put this JSP in your server and run it in your browser:


When you click on the button, the alert message will show you the server time and date at the time that the JSP was called.

Let the page sit for a few seconds and click the button again. You will see the same time. You can click on that button all day and see the same time because it's NOT interacting with the server.

If you right click on the page and view it's source, you will see:


This is the output from the JSP.
The new 'Date().toString()' call was made on the server where Javascript can't run. The alert function can only be activated on the browser.
The browser has no idea that the date/time we're looking at is the result of a java.util.Date object. For all it knows it was typed in manually by an HTML designer.


It is always a good idea for a beginning web programmer to get in the habit of viewing the HTML source from the browser. This is what your JSP/Servlet/PHP/Perl/ASP/CF programs are writing.
[ April 21, 2005: Message edited by: Ben Souther ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic