• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

unable to pass request paramenter to onload javascript method.

 
Ranch Hand
Posts: 2562
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 67620
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.)
 
Bartender
Posts: 1845
10
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would go with:

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67620
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 349
Hibernate Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would pick Stephan's option.
 
Monica Shiralkar
Ranch Hand
Posts: 2562
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67620
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic