admin管理员组文章数量:1321253
I'm trying to call a function and activate an alert through it in my JSP.
This is what i've done so far:
<html>
<head>
<script type="text/javascript">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
function myFunction( test )
{
alert( test );
}
</script>
<title>Success</title>
</head>
<body>
<c:set var="test" scope="request" value="${requestScope.userDetails }"></c:set>
<input type="button" id="sample_button" onclick="myFunction(${test.userName})" value="test">
</body>
</html>
What is wrong with my code?
I'm trying to call a function and activate an alert through it in my JSP.
This is what i've done so far:
<html>
<head>
<script type="text/javascript">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
function myFunction( test )
{
alert( test );
}
</script>
<title>Success</title>
</head>
<body>
<c:set var="test" scope="request" value="${requestScope.userDetails }"></c:set>
<input type="button" id="sample_button" onclick="myFunction(${test.userName})" value="test">
</body>
</html>
What is wrong with my code?
Share Improve this question asked Aug 21, 2013 at 7:18 newbienewbie 5372 gold badges8 silver badges13 bronze badges2 Answers
Reset to default 1You had a meta
element inside script
element which will throw an error while parsing the script block
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<script type="text/javascript">
function myFunction( test )
{
alert( test );
}
</script>
<title>Success</title>
</head>
<body>
<c:set var="test" scope="request" value="${requestScope.userDetails }"></c:set>
<input type="button" id="sample_button" onclick="myFunction(${test.userName})" value="test" />
</body>
</html>
In addition to that, You might also need to add a single quote inside the calling function
<input type="button" id="sample_button" onclick="myFunction('${test.userName}')" value="test">
Check for javascript errors & verify the generated HTML in browser
本文标签: htmlcalling Javascript function in JSPStack Overflow
版权声明:本文标题:html - calling Javascript function in JSP - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742094884a2420485.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论