[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

how to send java variable to javascript

Posted on 2009-04-20
3
Medium Priority
?
424 Views
Last Modified: 2012-05-06
I want the java variable value in my javascript, example below i want "sample" in alert not "str"
<html>
<body>
<% String str = "sample";%>
<script TYPE="text/javascript" LANGUAGE="JavaScript">
	window.onload = function (){
		var value = "<%=str%>";
		alert(value);
	}
</script>
</body>
</html>

Open in new window

0
Comment
Question by:Adwait Chitaley
  • 2
3 Comments
 
LVL 6

Accepted Solution

by:
JoachimMartinsen earned 150 total points
ID: 24183112
Try this:
<html>
<body>
<% str = "sample" %>
<script TYPE="text/javascript" LANGUAGE="JavaScript">
        window.onload = function (){
                var value = "<%=str%>";
                alert(value);
        }
</script>
</body>
</html>

Open in new window

0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24184137
Joachim: Why would that work?

achitaley: Your method is correct, but the page needs to be a JSP or similar
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24571835
???
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses
Course of the Month19 days, 17 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question