File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes script and javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply locked New topic
Author

script and javascript

Brucaliffo John
Greenhorn

Joined: Jan 20, 2009
Posts: 29
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

Joined: Jan 10, 2002
Posts: 61413
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Brucaliffo John
Greenhorn

Joined: Jan 20, 2009
Posts: 29
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

Joined: Jan 20, 2009
Posts: 29
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

Joined: Jan 10, 2002
Posts: 61413
    
  67

If your JavaScript syntax is incorrect, the script will not execute correctly. It's as simple as that.
Brucaliffo John
Greenhorn

Joined: Jan 20, 2009
Posts: 29
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Jan 10, 2002
Posts: 61413
    
  67

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

Joined: Jan 20, 2009
Posts: 29
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

Joined: Jan 20, 2009
Posts: 29
I get this html:


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

Thank You
Brucaliffo John
Greenhorn

Joined: Jan 20, 2009
Posts: 29
OK thank you for your precious support.
I resolved the problem.

John
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
So you saw the problem with



Eric
Brucaliffo John
Greenhorn

Joined: Jan 20, 2009
Posts: 29
So you saw the problem with

<script>var tooltip = ORCOBIO</script>

<script>var tooltip = ORCOBIO</script>

Eric


Yes
Brucaliffo John
Greenhorn

Joined: Jan 20, 2009
Posts: 29
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

Joined: Jan 10, 2002
Posts: 61413
    
  67

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

Joined: Jan 20, 2009
Posts: 29
I want to set the string on bottom of the browser.



Thank You
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
That would be window.status

Eric
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

I repeat:
In the future it is best to start new questions in new topics.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: script and javascript