Get ready for BLACK FRIDAY shopping starting in

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>
&lt;script type="text/javascript"&gt;
function run()
{
alert("run() function executing"
&lt;%
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()
%&gt;
alert("run() ended"
}
&lt;/script&gt;
</font id=code></pre id=code>
when the user clicks on a button
<pre id=code><font face=courier size=2 id=code>
&lt;input type="button" value="Click me!" onclick="run()" &gt;
</font id=code></pre id=code>
The problem I am having is that the ASP code (between the &lt;% %&gt; 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

Reply to this topic