I have below script where im passing scriptlet variable to javascript function. But there is no alert box displaying.. Please let me what im missing here..
<script language="JavaScript">
window.onload = function(){
<%
String res = request.getParameter("Message");
%>
var Value = "<%=res%>";
alert(Value);
document.Form.submit();
};
</script>
Thanks in advance
I have below script where im passing scriptlet variable to javascript function. But there is no alert box displaying.. Please let me what im missing here..
<script language="JavaScript">
window.onload = function(){
<%
String res = request.getParameter("Message");
%>
var Value = "<%=res%>";
alert(Value);
document.Form.submit();
};
</script>
Thanks in advance
Share Improve this question edited Oct 8, 2013 at 5:16 John asked Oct 8, 2013 at 5:15 JohnJohn 2,14113 gold badges36 silver badges45 bronze badges 4- remove the double quotes if you want the script to run and print res inside of the value variable – Jay Harris Commented Oct 8, 2013 at 5:19
-
Not a solution ! but for
script
taglanguage
is an obsolete attribute; try usingtype="text/javascript"
instead oflanguage="JavaScript"
– Vishal Commented Oct 8, 2013 at 5:20 - Thanks for the additional info, @Vishal – John Commented Oct 8, 2013 at 5:29
- All, its not displaying the alert box – John Commented Oct 8, 2013 at 6:08
3 Answers
Reset to default 1try this....
<script type="text/javascript">
window.onload = function(){
<%
String res = request.getParameter("Message");
%>
var Value = <%=res%>;
windows.alert(Value);
document.Form.submit();
};
</script>
What you need to use is <%= ... %>
. Try using this:
<script type="text/javascript">
window.onload = function(){
<%
String res = request.getParameter("Message");
%>
var Value = <%=res%>;
alert(Value);
document.Form.submit();
};
</script>
@John Why you creating scriptlet tag inside javascript. Instead try using this,
<%
String res = request.getParameter("Message");
%>
<script type="text/javaScript">
window.onload = function(){
var Value = "<%=res%>";
alert(Value);
document.Form.submit();
};
</script>
else try using jquery plugin for your purpose,
<%
String res = request.getParameter("Message");
%>
<script type="text/javaScript">
$(document).ready(function() {
var Value = "<%=res%>";
alert(Value);
$('form#myForm').submit();
});
</script>