JElster
asked on
How to pass var to JS
Hi..
What's wrong with this?
msg = "Hello"
Response.Write("<input type='button' onclick='alertl(<%=msg%>)' value='Hil'>")
What's wrong with this?
msg = "Hello"
Response.Write("<input type='button' onclick='alertl(<%=msg%>)'
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Invalid character
Response.Write("<input type='button' onclick='alert("<%=msg
-------------------------- ---------- ---------- --------^
Response.Write("<input type='button' onclick='alert("<%=msg
--------------------------
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Me either...
Get
Uncaught TypeError: string is not a function
looks like this
<input type='button' onclick='alert("Hello")' value='Hil'>
Get
Uncaught TypeError: string is not a function
looks like this
<input type='button' onclick='alert("Hello")' value='Hil'>
did you get it to work? i just tested the exact code on my end and it's working...
why was the assisted question selected as a valid answer? it is syntactically incorrect both on the server side and on the javascript it generates, and will not work.
why was the assisted question selected as a valid answer? it is syntactically incorrect both on the server side and on the javascript it generates, and will not work.
ASKER
no.. doesn't like the alert. ??????????????????
console.log works - I don't need the alert. just need to call a function.
Thought the other code was ok, sorry
thx again for your help
console.log works - I don't need the alert. just need to call a function.
Thought the other code was ok, sorry
thx again for your help
Looking at your question as to what you asked for, BM's answer http:Q_28502550.html#a40276080 is the correct way out of the two accepted. The first answer by Deepak Subburajan will render as below
Overall, you probably want to get in the habit of using button now instead of input type="button". And keep your functions in your js. Below would be my take on modernizing what we do in asp. Static sample http://jsbin.com/gahozi/1/edit
<input type="button" onclick="alert"1(" hello')' value="Hil">
and it should be<input type="button" onclick="alert"(" hello")" value="Hil">
2 errors in the first. the 1 before the (" hello and the single/double quoting is wrong.Overall, you probably want to get in the habit of using button now instead of input type="button". And keep your functions in your js. Below would be my take on modernizing what we do in asp. Static sample http://jsbin.com/gahozi/1/edit
<%
msg = "Hello"
%>
<!DOCTYPE html>
<html>
<head>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<script>
$(function(){
$('.test').on('click',function(){
var say=$(this).attr('data-item');
alert(say);
});
});
</script>
<meta charset="utf-8">
<title>test</title>
</head>
<body>
<button class="test" data-item="hello">Hil</button>
<%
response.write "<button class='test' data-item='"&msg&"'>Hil</button>"
%>
</body>
</html>
Response.Write("<input type='button' onclick='alert("<%=msg%>")