• Post Reply Bookmark Topic Watch Topic
  • New Topic

unable to pass request paramenter to onload javascript method.  RSS feed

 
Monica Shiralkar
Ranch Hand
Posts: 919
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a java script which takes parameter.This javascript is in body Onload. Now this paremeter comes from . I am unable to pass the parmeter to javascript because javascript is in onload and paramenter is read later than onload.Please advice




This does not work for reason explained.Please advice how to make it work.

thanks
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem has to do with the fact your serverside language and JavaScript do not interact like that. View the page source, do you see the variables latitude/longitude defined anywhere on the page?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please read this article to understand how JSP operates and why your code makes no sense.

You can use the EL (not obsolete scriptlets) to "write" the values into the script markup, but you cannot pass values directly. (See article.)
 
Stefan Evans
Bartender
Posts: 1836
10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would go with:

 
Shashank Gollapudi
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As you already have the values in the JSP, i think you can directly use them using jsp expressions

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shashank Gollapudi wrote:As you already have the values in the JSP, i think you can directly use them using jsp expressions

Not good advice. Using scriptlets in a JSP is an obsolete and outdated poor practice that should no longer be encouraged. I think 12 years is plenty of time to come up to speed on the EL!
 
Ananth Chellathurai
Ranch Hand
Posts: 349
Eclipse IDE Hibernate Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would pick Stephan's option.
 
Monica Shiralkar
Ranch Hand
Posts: 919
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Stefan and everyone. It worked perfectly. I want to understand that:

- Why passing parameters like this is working and not they way I was passing?
- I understand Bear Bibeault's advice that scriplet should not be used as adviced in Shashank's code.However just out of curiosity I want to know why it would work and not they way i coded.

thanks...
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Monica. Shiralkar wrote:
- Why passing parameters like this is working and not they way I was passing?

Did you read the article? There is no parameter passing going on here. The EL expressions are simply writing the values into the HTML/JavaScript markup.

Do a View Source on the page for both "versions". What do you see?
 
Shashank Gollapudi
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:
Shashank Gollapudi wrote:As you already have the values in the JSP, i think you can directly use them using jsp expressions

Not good advice. Using scriptlets in a JSP is an obsolete and outdated poor practice that should no longer be encouraged. I think 12 years is plenty of time to come up to speed on the EL!


Thanks for correcting me Bear, i would take your advice
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!