Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 26th, 2006, 12:49 AM
Friend of Wrox
 
Join Date: Jan 2006
Posts: 180
Thanks: 1
Thanked 1 Time in 1 Post
Send a message via ICQ to dpkbahuguna Send a message via MSN to dpkbahuguna Send a message via Yahoo to dpkbahuguna
Default How to Call Sub in ASP

Hello all!

    I am beginner in ASP. I have to call a sub through <select>'s event onchange() how can i do that. I did something related to it but i couldnt do it. pls help here..

My ASP code is:
---------------------------------------------------------
<%@ language = vbscript%>
<%
    sub x()
        response.write("this is printing")
    end sub
%>


<html>
    <select name = dept Onchange = "x()">
        <option value = 1> > one </option>
        <option value = 2> > two </option>
    </select>
<html>
-----------------------------------------------------

why this is not working?

Thanks !!

DPK..
__________________
DPK..
 
Old December 31st, 2006, 04:04 PM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 198
Thanks: 2
Thanked 0 Times in 0 Posts
Send a message via MSN to itHighway
Default

The reason is you are trying to execute ASP Script at OnChange Event.
At onChange you can only call JavaScript function NOT ASP Script.

However, if you submit the form at onChange Event and pass a value in query string and then read that value in sub procedure then you would be able to display the values in procedure.



 
Old January 1st, 2007, 05:01 AM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Actually, you can call vbscript in a browser, as long as it is an IE browser.

Here is a little sample:

Code:
<script language='vbscript'>

sub btnTest_onclick
   msgbox "Here is one way..."
end sub

sub TestTwo
   msgbox "Well, another way!?"
end sub

</script>

<INPUT name='btnTest' type='button' value='VbScript Test' />
<INPUT name='btnTestTWo' type='button' value='VbScript Test Two' onclick='TestTwo' />
The issue with your sample is that you are declaring the code as being server side, where you need it to be client side - that is, running in the browser.

Woody Z
http://www.learntoprogramnow.com
 
Old January 1st, 2007, 05:39 AM
Friend of Wrox
 
Join Date: Jan 2006
Posts: 180
Thanks: 1
Thanked 1 Time in 1 Post
Send a message via ICQ to dpkbahuguna Send a message via MSN to dpkbahuguna Send a message via Yahoo to dpkbahuguna
Default


A Great Thank and very very happy new year to you both
"Woodyz" and "ItHighway".

DPK..
 
Old January 1st, 2007, 06:04 AM
Friend of Wrox
 
Join Date: Jan 2006
Posts: 180
Thanks: 1
Thanked 1 Time in 1 Post
Send a message via ICQ to dpkbahuguna Send a message via MSN to dpkbahuguna Send a message via Yahoo to dpkbahuguna
Default

Hi woodyz yes your code is working fine but will u give me the code to call this event on <select> (combobox) event like onChange.
I did it but i am unable to call it.

Thanks waiting for reply....


Quote:
quote:Originally posted by woodyz
 Actually, you can call vbscript in a browser, as long as it is an IE browser.

Here is a little sample:

Code:
<script language='vbscript'>

sub btnTest_onclick
   msgbox "Here is one way..."
end sub

sub TestTwo
   msgbox "Well, another way!?"
end sub

</script>

<INPUT name='btnTest' type='button' value='VbScript Test' />
<INPUT name='btnTestTWo' type='button' value='VbScript Test Two' onclick='TestTwo' />
The issue with your sample is that you are declaring the code as being server side, where you need it to be client side - that is, running in the browser.

Woody Z
http://www.learntoprogramnow.com
DPK..
 
Old January 1st, 2007, 06:10 AM
Friend of Wrox
 
Join Date: Jan 2006
Posts: 180
Thanks: 1
Thanked 1 Time in 1 Post
Send a message via ICQ to dpkbahuguna Send a message via MSN to dpkbahuguna Send a message via Yahoo to dpkbahuguna
Default

thanks IThighway,

   But how can i submit button in ,select> onchange..?

Quote:
quote:Originally posted by itHighway
 The reason is you are trying to execute ASP Script at OnChange Event.
At onChange you can only call JavaScript function NOT ASP Script.

However, if you submit the form at onChange Event and pass a value in query string and then read that value in sub procedure then you would be able to display the values in procedure.



DPK..
 
Old January 1st, 2007, 11:41 AM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by dpkbahuguna
 Hi woodyz yes your code is working fine but will u give me the code to call this event on <select> (combobox) event like onChange.
I did it but i am unable to call it.

Thanks waiting for reply....
I bet you would find it useful to do a search on the web for this sort of thing. There are numerous tutorial and code snippets on how to use these events. Of course, you are probably going to be much better off doing this with Javascript rather than VBScript.

However - I might not be understanding your question. Is it that you want the form to submit whenever the user changes the selection in the dropdown? That can be done the same way (either with javascript or vbscript) by handling the onchange event. Or perhaps you are asking how to "reponse.write" something to the browser without posting back - in which case you'll need client side scripts (again, either Javascript or vbscript) that manipulate the document object.

It might be useful to you to better describe what you are trying to do.

Here is the code for running vbscript with the onchange event:
Code:
<script language='vbscript'>

sub DropdownTest
   msgbox "This is the dropdown test"
end sub

sub cboTestTwo_onchange
   msgbox "This is the second dropdown test"
end sub

</script>

<select name='cboTest'onchange='DropdownTest'>
<option value='1'>One</option>
<option value='2'>Two</option>
<option value='3'>Three</option>
<option value='4'>Four</option>
</select>
<br/>
<select name='cboTestTwo'>
<option value='5'>Five</option>
<option value='6'>Six</option>
<option value='7'>Seven</option>
<option value='8'>Eight</option>
</select>
Woody Z
http://www.learntoprogramnow.com
 
Old January 1st, 2007, 11:44 AM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by dpkbahuguna
 Hello all!

    I am beginner in ASP. I have to call a sub through <select>'s event onchange() how can i do that. I did something related to it but i couldnt do it. pls help here..

My ASP code is:
---------------------------------------------------------
<%@ language = vbscript%>
<%
    sub x()
        response.write("this is printing")
    end sub
%>


<html>
    <select name = dept Onchange = "x()">
        <option value = 1> > one </option>
        <option value = 2> > two </option>
    </select>
<html>
-----------------------------------------------------

why this is not working?

Thanks !!

DPK..
Perhaps I am misunderstanding your request entirely.
Please clarify what you are trying to do.

The reason this code does not work is because the code what is within the <% %> markup runs on the server side, and the onchange event is handled on the client side. They are running in different contexts on different machines.

So this brings up the question: What is the RESULT you are trying to achieve?

Woody Z
http://www.learntoprogramnow.com
 
Old January 31st, 2007, 03:46 PM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 198
Thanks: 2
Thanked 0 Times in 0 Posts
Send a message via MSN to itHighway
Default

I am sorry, did not understand what you are trying to do

http://www.ithighway.co.uk/





Similar Threads
Thread Thread Starter Forum Replies Last Post
Call outlook ASP.Net dani_adam71 .NET Framework 2.0 1 October 27th, 2008 08:15 AM
How to call C# COM overloaded functions from ASP? khaledriyal C# 0 October 11th, 2005 03:13 AM
How to call VC++ DLL from ASP/ASP.net? leesoon Classic ASP Professional 0 December 9th, 2004 10:06 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.