52
rated 0 times
[
57]
[
5]
/ answers: 1 / hits: 17859
/ 9 Years ago, sun, march 22, 2015, 12:00:00
I want to passing a java String variable to the javascript function parameter using jsp expression tag.Below is my jsp page.
First.jsp
<!DOCTYPE html PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN http://www.w3.org/TR/html4/loose.dtd>
<html>
<head>
<meta http-equiv=Content-Type content=text/html; charset=ISO-8859-1>
<title>Insert title here</title>
<script>
function stringGenerate(str){
var x = document.getElementsByTagName(input);
x[0].value = str;
}
function numberGenerate(num){
var x = document.getElementsByTagName(input);
x[1].value = num;
}
</script>
</head>
<body>
<%
String num =1234567890;
String str = abcdefghij;
%>
<input type=text name=string readonly=readonly/>
<input type=text name=number readonly=readonly/><br/><br/>
<input type=button value=String Generate onclick= stringGenerate(<%=str %>) />
<input type=button value=Number Generate onclick= numberGenerate(<%=num %>) />
</body>
</html>
When I click on the button with value Number Generate,then the num variable value(1234567890) will display on the textbox(name=number) but when I click on the button with value String Generate,then there is nothing display on the corresponding text box(name=string).Here both num and str are string type varible but why only num variable value is displayed on textbox and why not str variable value is displayed?
More From » java