469,929 Members | 1,726 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,929 developers. It's quick & easy.

calling an ASP function

Well I'm a newbie in ASP but still I can't understand the reason to get an
error message when I click on the button.
The following code is supposed to display a message when pressing the
button?

<%
response.write("<input type=""button"" name=""radio_connection""
value=""narrowband"" onClick=""setNarrowband()"">")

Function setNarrowband()
response.write("BROAD")
End Function
%>

Jul 19 '05 #1
5 8911
Nooooooo

The onclick event works in the client side.

So you should write client side code for that.
--
Roji. P. Thomas
SQL Server Programmer
--------------------------------------
"Γιώργος Στάθης" <ge****@sch.gr> wrote in message
news:3f******@news.sch.gr...
Well I'm a newbie in ASP but still I can't understand the reason to get an
error message when I click on the button.
The following code is supposed to display a message when pressing the
button?

<%
response.write("<input type=""button"" name=""radio_connection""
value=""narrowband"" onClick=""setNarrowband()"">")

Function setNarrowband()
response.write("BROAD")
End Function
%>

Jul 19 '05 #2
Absolutely not.

The ASP code is executed on the server and nothing, except the result,
remain inside the HTML code when the page is displayed in the browser. If
you look at the source code from the browser, you will see that the function
setNarrowband() is totally missing. You need to use <script></script> tags
inside the HTML, with Javascript or VBScript code.

Also, when the HTML is displayed, you cannot write to it with a write
statement. It's something more complicated than that. Search Google for
DHTML (Dynamic HTML).

Try something like this instead:

<% response.write ........ %>

<script language=vbscript>
function SetNarrowBand()
msgbox "BROAD"
end function
</script>

There are other aspects, like the fact that the function setNarrowband may
or may not return a value and, if it returns a value, that this value can be
true of false. Different events, like onSubmit, onMouseOver, onClick, etc.,
may have a different response in each of these cases.

It will also explains why you will see something like
onClick="javascript:setNarrowband();" or
onClick="javascript:void(setNarrowband());" (Use javascript even if the
underlying function is coded in VBScript).

ASP.NET, which is not the same thing as ASP, bear some similitude to what
you have tried to do.

S. L.
"Γιώργος Στάθης" <ge****@sch.gr> wrote in message
news:3f******@news.sch.gr...
Well I'm a newbie in ASP but still I can't understand the reason to get an
error message when I click on the button.
The following code is supposed to display a message when pressing the
button?

<%
response.write("<input type=""button"" name=""radio_connection""
value=""narrowband"" onClick=""setNarrowband()"">")

Function setNarrowband()
response.write("BROAD")
End Function
%>

Jul 19 '05 #3

"Γιώργος Στάθης" wrote:
The following code is supposed to display a message when pressing the
button?

<%
response.write("<input type=""button"" name=""radio_connection""
value=""narrowband"" onClick=""setNarrowband()"">")

Function setNarrowband()
response.write("BROAD")
End Function
%>


<%@ Language=VBScript %>
<%
response.write("<script type=""text/javascript"">" & vbCrLf & _
"function setNarrowband() {" & vbCrLf & _
" document.write(""BROAD"");" & vbCrLf & _
" }" & vbCrLf & _
"</script>" & vbCrLf)
response.write("<input type=""button"" name=""radio_connection""
value=""narrowband"" onClick=""setNarrowband()"" />")
%>

--
Roland

This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose.


Jul 19 '05 #4
Performing a document.write after the page has loaded (since a user can't
really click on a button until the page has been rendered) is going to to
unpredictable things on different browsers. Also, where on the page is this
going to go? At the end?

I think DHTML would be the right angle (but again, the original poster
should go to a client-side group for the technical details).

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/


"Roland Hall" <nobody@nowhere> wrote in message
news:#U**************@tk2msftngp13.phx.gbl...

"Γιώργος Στάθης" wrote:
The following code is supposed to display a message when pressing the
button?

<%
response.write("<input type=""button"" name=""radio_connection""
value=""narrowband"" onClick=""setNarrowband()"">")

Function setNarrowband()
response.write("BROAD")
End Function
%>


<%@ Language=VBScript %>
<%
response.write("<script type=""text/javascript"">" & vbCrLf & _
"function setNarrowband() {" & vbCrLf & _
" document.write(""BROAD"");" & vbCrLf & _
" }" & vbCrLf & _
"</script>" & vbCrLf)
response.write("<input type=""button"" name=""radio_connection""
value=""narrowband"" onClick=""setNarrowband()"" />")
%>

--
Roland

This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose.

Jul 19 '05 #5
"Aaron Bertrand - MVP" wrote:
Performing a document.write after the page has loaded (since a user can't
really click on a button until the page has been rendered) is going to to
unpredictable things on different browsers. Also, where on the page is this going to go? At the end?

I think DHTML would be the right angle (but again, the original poster
should go to a client-side group for the technical details).


I agree with all points you made. This example replaces the page with only
the text written. It is not a viable solution but it was an answer of how
to make, what he wanted, functional.

--
Roland

This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose.
Jul 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Muthu | last post: by
6 posts views Thread by jchao123 | last post: by
1 post views Thread by Jesse McGrew | last post: by
5 posts views Thread by Nick Flandry | last post: by
2 posts views Thread by Geler | last post: by
15 posts views Thread by dspfun | last post: by
11 posts views Thread by briankirkpatrick | last post: by
16 posts views Thread by teju | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.