Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update SQL Server 2005 database from javascript

Status
Not open for further replies.

lianaent

Programmer
Apr 26, 2007
10
US
I'm pretty new to javascript, but I've got a client-side shopping cart that I've copied from a website and modified for my own use. I'm working in asp.net 2.0. When I add an item to my shopping cart I'm updating my SQL Server 2005 database with a flag that indicates that the item is pending a sale and currently not available.

However, when I delete an item from the shopping cart (handled totally in javascript) I want to update my database and reset the flag to available. I haven't got a clue how to update my database from javascript.

Any help is greatly appreciated!
TIA,
Larry
 
(Yes, I know javascript is client-side. But once the user is in the cart, there's no way for server-side code to know what they've clicked, or even which asp.net form they used to open the cart. If there was only one asp.net form that opened the cart, then I could update a field in that form from javascript. Even then though, the form wouldn't know when a field was updated and so would have to constantly scan for changes.)

What do other people do in this situation?

Thanks for reading and pondering this!
Larry
 
I found one not-so-clean way to do this:

In the delete item javascript function I added a window.open back to my ordering page, but with a "Cancel" in the querystring. In the asp.net ordering page, if the querystring has the "Cancel" in it, then I set the flag back to available.

While this works, it's not so pretty. Every time an item is deleted a new page opens up. Also, I haven't figured out what to do yet if they hit "Clear Cart.
 
Okay, figured out, nevermind.

When I open the order page back up with the "Cancel", after setting the flag back to available, I'm closing the page with:

Response.Write("<script language='javascript'> { self.close() }</script>")

To the user, all they see is a flicker.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top