Forums
This topic is locked
Running ASP from a Javascript function?
Posted 25 Jul 2006 12:59:30
1
has voted
25 Jul 2006 12:59:30 Mark Stephenson posted:
Hi, is it possible to run a section of ASP code when a javascript function is called? The reason I ask is that I am having a problem... I want to run the function <pre id=code><font face=courier size=2 id=code>
<script type="text/javascript">
function run()
{
alert("run() function executing"
<%
var insertCommand = Server.CreateObject("ADODB.Command"
insertCommand.ActiveConnection = MM_connSQL_Worktypes_STRING
insertCommand.CommandText = "UPDATE dbo.tblWTDStatus SET strActioned = 'LFC' WHERE strActioned = 'hahah'"
insertCommand.CommandType = 1
insertCommand.CommandTimeout = 0
insertCommand.Prepared = true
insertCommand.Execute()
%>
alert("run() ended"
}
</script>
</font id=code></pre id=code>
when the user clicks on a button
<pre id=code><font face=courier size=2 id=code>
<input type="button" value="Click me!" onclick="run()" >
</font id=code></pre id=code>
The problem I am having is that the ASP code (between the <% %> tags appears to be running when the page is refreshed, not when run() is called. The alert boxes in run() are displaying when the button is clicked though!
Can anyone help me? I need the ASP code to be executed when the button is clicked.
Thanks in advance
Mark