Calling av function when clicking a button

  • Thread starter Øyvind Isaksen
  • Start date
Ø

Øyvind Isaksen

Hi!

I have made a function calles "send()". When I click a button, I want the
function to be prosessed.
This is the code that I have made, but it dont work:



<%function send()

Value = MsgBox ("Trykk på en knapp...",4,"Trykk en knapp vindu")
If Value = 6 Then
MsgBox "You pushed Yes!"
Else
MsgBox "You pushed No!"
End If

end function%>


input type="button" value="Utfør" onclick="send()" name="Utfoer"/>



What is wrong here? Thanks for your help :)
Regards Øyvind.
 
M

Matt Simner

Hi,

There's a bit of a mixture of client-side and server-side code here...
You've posted to an ASP group (which is server-side) - but I'll see
if I'm on the right lines with what you're trying to do ....

Any code within <% ... %> markers means it runs server-side (i.e. it
runs on the web server 'before' the HTML has been written out) and
anything in the HTML elements - like 'OnClick="send()"' is client-side
(runs in the browser on the user's machine - after the HTML has been
written out). Normally, you'd expect to run anything with Popups
(MsgBox) on the client-side.

It looks like you need to change your send function to be within a
client-side <SCRIPT> block and this will all work in the browser
without going back to the Web Server.

so ...

<html>
<head>

<script language="vbscript">

function send()

Value = MsgBox ("Trykk på en knapp...",4,"Trykk en knapp vindu")
If Value = 6 Then
MsgBox "You pushed Yes!"
Else
MsgBox "You pushed No!"
End If

end function

</script>

</head>

<body>

<form>
<input type="button" value="Utfør" onclick="send()" name="Utfoer"/>
</form>

</body>
</html>


.... should do the trick.

Just another point. If this is going to run on a browser other than
Internet Explorer - you'll probably need to rewrite you script into
JavaScript, as this is more supported 'cross-browser'.

Hope that helps - and I haven't misunderstood.

Cheers,

Matt Simner
 
A

Andrew Durstewitz

There are 2 ways you could do it. One is use ASP.NET which support
object oriented code. The other is to redirect the user to another ASP
page when the button is clicked. That page can call the function when
loading.

Since ASP3.0 is a scripted language you don't have much in the way of
options.

hth,
Andrew

DEVBuilder.org, http://www.DEVBuilder.org
ASP,ASP.NET,VB.NET,PHP,Java,and SQL Support, all in one place.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,091
Messages
2,570,605
Members
47,225
Latest member
DarrinWhit

Latest Threads

Top