Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

alert function

 
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
 
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 ]
 
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.
 
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
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • 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 VI Editor Redhat
  • 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 ]
 
It is no measure of health to be well adjusted to a profoundly sick society. -Krishnamurti Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic