Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
    Bookmark Topic Watch Topic
  • New Topic

script and javascript

 
Brucaliffo John
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!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65116
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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
Author and ninkuma
Marshal
Pie
Posts: 65116
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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!
 
Eric Pascarello
author
Rancher
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
Author and ninkuma
Marshal
Pie
Posts: 65116
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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
Rancher
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
Author and ninkuma
Marshal
Pie
Posts: 65116
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Report post to moderator
That would be window.status

Eric
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65116
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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.
 
    Bookmark Topic Watch Topic
  • New Topic