Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. 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 Databases 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 13th, 2010, 05:48 PM
Authorized User
 
Join Date: Dec 2009
Posts: 85
Thanks: 16
Thanked 0 Times in 0 Posts
Default triggering a db function

Hi there

I've got this code running which shows/hides a layer:

<div id="pnl"><a href="#" onclick="showHide('<%=intid%>')"><span id="snone">Reveal text here</span></a>
</div>

Onclick, I also need to trigger a database update and email send - is there a way I can do this without navigating away from the page or changing the state of the page?

could I use an include file for the update/email send?

thanks

Adam
 
Old December 14th, 2010, 02:59 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

The onclick fires at the client, so you somehow need a way to run some code on the server. For this, you could use AJAX, combined with for example ASP.NET Page Methods or Web Services. To make the AJAX part a little easier, you may want to look into jQuery.

Even if you can't use ASP.NET, you can still request (or post to) some server side classic ASP page that updates the database. An include won't do you any good here, as it's included at the server, not the client.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old December 14th, 2010, 09:10 AM
Authorized User
 
Join Date: Dec 2009
Posts: 85
Thanks: 16
Thanked 0 Times in 0 Posts
Default triggering a db function on click

Hi Imar

thanks for that

I've followed your lead and investigated using ajax -this is what I've come up with so far:

<script language="javascript">
function update_customer(str)
{
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlht tp.responseText;
}
}
//xmlhttp.open("GET","customer_update.asp?q="+str,tr ue);


xmlhttp.open("GET","customer_update.asp?q="+str+"& id="+<%=intproductid%>,true);


xmlhttp.send();
}
</script>


' and this is the action to trigger it particularly the update_customer(this.value)

<div id="pnl"><a href="javascript:void();" onclick="showHide('<%=intproductid%>'); update_customer(this.value)"><span id="snone">Action Text Here</span></a>
</div>

2 things:

1. I'm not actually sure if I've got the right syntax for performing 2 x javascript actions using the onclick
2. It's not actually triggering the update

Are you able to help?

thanks

Adam

And this is the onChange
 
Old December 14th, 2010, 09:31 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Adam,

Does this.value produce a value? I doubt it does, so your code may never fire.

Rather than building your own AJAX stuff, have you considered jQuery? Makes these kind of things a snap...

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old December 14th, 2010, 10:04 AM
Authorized User
 
Join Date: Dec 2009
Posts: 85
Thanks: 16
Thanked 0 Times in 0 Posts
Default triggering a db function on click

Hi Imar

No,I haven't actually - where would be a good point of reference to start from for this particular function?

thanks

Adam
 
Old December 14th, 2010, 10:08 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

http://jquery.com/ would be a great start for a general introduction and download. Then the Ajax category could be the next stop: http://api.jquery.com/category/ajax/

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
adamhw (December 14th, 2010)
 
Old December 14th, 2010, 10:28 AM
Authorized User
 
Join Date: Dec 2009
Posts: 85
Thanks: 16
Thanked 0 Times in 0 Posts
Default triggering a db function on click

one more thing Imar so I'm not starting on the wrong path, which function would I use on http://api.jquery.com/category/ajax/

I'm presuming I'd need to use the jquery.get()?

thanks

adam
 
Old December 14th, 2010, 10:48 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Yep, that's what I would try first...

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old December 14th, 2010, 10:56 AM
Authorized User
 
Join Date: Dec 2009
Posts: 85
Thanks: 16
Thanked 0 Times in 0 Posts
Default triggering a db function on click

thanks Imar

I may need to come back to you when I'm a bit further down the line if that's OK?

thanks

Adam
 
Old December 14th, 2010, 11:20 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Sure; that's what these forums are for.....

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
adamhw (December 14th, 2010)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Triggering - cancer10 Classic ASP Databases 1 May 5th, 2007 05:15 AM
CustomValidation not triggering jacob ASP.NET 1.x and 2.0 Application Design 2 December 1st, 2005 04:31 PM
Triggering a javascript function badgolfer ASP.NET 1.0 and 1.1 Basics 1 June 30th, 2004 06:31 AM
Returning a result from a db function not allowed? treycarroll Beginning PHP 2 March 17th, 2004 07:53 PM
Validation is not triggering bmains ASP.NET 1.0 and 1.1 Professional 2 February 11th, 2004 02:23 PM





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