Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
    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
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

script and javascript

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hello,
I have a script tag in my jsp:
<script> var tooltip = <%=tooltipMenu%> </script>
I need to use tooltip variable in a javascript file (meunExpandable.js).
How can I do that?

Thank You very much!
 
Marshal
Posts: 67415
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Report post to moderator
Except for forgetting the quotes around the string, what's the problem?

Once loaded, all JavaScript is in the same namespace so whether script is in a .jjs file or not is moot.`Of course, you can;t reference something before it's defined, so order counts if the script is inline.
 
Brucaliffo John
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Report post to moderator
I HAVE THIS IN MY JSP:
<script>var tooltip = "<%=tooltipAperto%>"</script>
<script type="text/javascript" src="scripts/menuExpandable.js"></script>

AND THIS IN MY JS FILE:
alert(tooltip);

but erroro occur in js file: "tooltip cannot be resolved".

why?

Thank You

 
Brucaliffo John
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Report post to moderator
sorry this is my code:

MY JSP:
<script>var tooltip = <%=tooltipMenu%></script>
<script type="text/javascript" src="scripts/menuExpandable.js"></script>

MY JS FILE:
alert(tooltip);

but erroro occur in js file: "tooltip cannot be resolved".
 
Bear Bibeault
Marshal
Posts: 67415
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Report post to moderator
If your JavaScript syntax is incorrect, the script will not execute correctly. It's as simple as that.
 
Brucaliffo John
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Report post to moderator
but is alert(tooltip); incorrect?
or is variable.title = tooltip; incorrect?

That should be correct.

Tell me where I'm wrong.

Thank You so!
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Report post to moderator

Brucaliffo John wrote:sorry this is my code:

MY JSP:
<script>var tooltip = <%=tooltipMenu%></script>
<script type="text/javascript" src="scripts/menuExpandable.js"></script>

MY JS FILE:
alert(tooltip);

but erroro occur in js file: "tooltip cannot be resolved".



Look at the source code that is generated. View Source on your browser, look what is ouputted.

Eric
 
Bear Bibeault
Marshal
Posts: 67415
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Report post to moderator
LOOK at your JavaScript. Not in your source, but what is being delivered to the browser (do a View Source).

Is it the correct syntax?
 
Brucaliffo John
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Report post to moderator
I'm sorry,
Are you talking about HTML generated?
The html code is correct, the page is all right.
it's just I can't access var tooltip I declared in jsp.
 
Brucaliffo John
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Report post to moderator
I get this html:


and the alert window shows "undefined"
but tooltip should be defined.
I'm wrong?

Thank You
 
Brucaliffo John
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Report post to moderator
OK thank you for your precious support.
I resolved the problem.

John
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Report post to moderator
So you saw the problem with



Eric
 
Brucaliffo John
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Report post to moderator

So you saw the problem with

<script>var tooltip = ORCOBIO</script>

<script>var tooltip = ORCOBIO</script>

Eric



Yes
 
Brucaliffo John
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Report post to moderator
another little question:
I have to set onmouseover value in my javascript file.
variable.title = "test"; works fine
variable.onmouseover = "test"; doesn't work
why?
wich is the correct syntax to set onmouseover?

Thank You!
 
Bear Bibeault
Marshal
Posts: 67415
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Report post to moderator
In the future it is best to start new questions in new topics.

onmouseover expects to be assigned a function, you are giving it a string. What do you expect that to do for you?
 
Brucaliffo John
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Report post to moderator
I want to set the string on bottom of the browser.



Thank You
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Report post to moderator
That would be window.status

Eric
 
Bear Bibeault
Marshal
Posts: 67415
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Report post to moderator
I repeat:

In the future it is best to start new questions in new topics.

 
No matter. Try again. Fail again. Fail better. This time, do it with this 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
    Bookmark Topic Watch Topic
  • New Topic