 |
| 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
|
|
|
|

December 13th, 2010, 05:48 PM
|
|
Authorized User
|
|
Join Date: Dec 2009
Posts: 85
Thanks: 16
Thanked 0 Times in 0 Posts
|
|
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
|
|

December 14th, 2010, 02:59 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|

December 14th, 2010, 09:10 AM
|
|
Authorized User
|
|
Join Date: Dec 2009
Posts: 85
Thanks: 16
Thanked 0 Times in 0 Posts
|
|
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
|
|

December 14th, 2010, 09:31 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|

December 14th, 2010, 10:04 AM
|
|
Authorized User
|
|
Join Date: Dec 2009
Posts: 85
Thanks: 16
Thanked 0 Times in 0 Posts
|
|
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
|
|

December 14th, 2010, 10:08 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|
The Following User Says Thank You to Imar For This Useful Post:
|
|
|

December 14th, 2010, 10:28 AM
|
|
Authorized User
|
|
Join Date: Dec 2009
Posts: 85
Thanks: 16
Thanked 0 Times in 0 Posts
|
|
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
|
|

December 14th, 2010, 10:48 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Yep, that's what I would try first...
Imar
|
|

December 14th, 2010, 10:56 AM
|
|
Authorized User
|
|
Join Date: Dec 2009
Posts: 85
Thanks: 16
Thanked 0 Times in 0 Posts
|
|
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
|
|

December 14th, 2010, 11:20 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Sure; that's what these forums are for.....
Imar
|
|
The Following User Says Thank You to Imar For This Useful Post:
|
|
|
 |