Solved

Update database without refreshing page

Posted on 2012-03-14
4
412 Views
Last Modified: 2012-06-27
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Shopping Cart</title>
<style type="text/css">
<!--
.delbtn {
	background: url("/a/delbtn-x.png") no-repeat;
	font-weight: bold;
	text-decoration: none;
	display: block;
}
.delbtn:hover {
	background: url("/a/delbtn.png") no-repeat;
}
-->
</style>
</head>
<body>
<iframe name="brain" src="" width="0" height="0" marginwidth="0" marginheight="0" frameborder="0"></iframe>
<cfquery name="ServicesInfo" datasource="NEWSB">
 select *
 from services
 where id =1

</cfquery>
<cfoutput query="ServicesInfo">
 <table border="1">
  <tr>
   <td>Title</td>
   <td>Remove</td>
  </tr>
  <tr>
   <td>#package#</td>
   <INPUT CLASS="delbtn" TYPE="text" NAME="#Title#" VALUE=" &nbsp; " SIZE="4" MAXLENGTH="4" onChange="brain.location='/service/update.cfm?id=4;">
   </td>
  </tr>
 </table>
</cfoutput>
</body>
</html>

Open in new window


This example shopping cart test page will be open to the public on the web so it has to work in all major browsers.

I want to update a choice in our sql2000 database, similar to what Netfix does when one clicks on the big X to remove a DVD from the list of DVD titles in the "Your Queue" page. The image here is the X. That works here. That's not the problem.

In any event, the code I'm using does not work. I want to use the best possible choice, even if it means I take some time to understand it, and it may take more than one question.

Can someone help, or point me to a clear, basic example how to achieve what I want. I'm a novice and need this explained, what needs to be done to call my update.cfm without moving away from the current page or refreshing it.

Also, I'm not at all certain if using iframe could be a problem, if it could be seen as a pop up.


Open in new window

0
Comment
Question by:Qsorb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 250 total points
ID: 37723569
Here http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=JavaScriptFcns_03.html is the docs for "ColdFusion.Ajax.submitForm".  That should be what you are looking for.  It will take some study to get all of what you want working.  The iframe probably has nothing to do with it.
0
 
LVL 16

Assisted Solution

by:Gurpreet Singh Randhawa
Gurpreet Singh Randhawa earned 250 total points
ID: 37726016
why not use jquery here like this:

$(document).ready(function() {
$('.delbtn').click(function () {
var title = $('#title').val();
var data = 'title=' + title;
$.ajax({
type:"POST",
url:"complete.cfm",
data: data,
success: function (html) {
$('#message').html(html);
$("#refreshDiv").load("callthesamepage");
}
});
return false;
});
});

Open in new window


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Shopping Cart</title>
<style type="text/css">
<!--
.delbtn {
      background: url("/a/delbtn-x.png") no-repeat;
      font-weight: bold;
      text-decoration: none;
      display: block;
}
.delbtn:hover {
      background: url("/a/delbtn.png") no-repeat;
}
-->
</style>
</head>
<body>
<div is="message"></div>
<div id="refreshMe">
<cfquery name="ServicesInfo" datasource="NEWSB">
 select *
 from services
 where id =1

</cfquery>
<cfoutput query="ServicesInfo">
 <table border="1">
  <tr>
   <td>Title</td>
   <td>Remove</td>
  </tr>
  <tr>
   <td>#package#</td>
   <INPUT CLASS="delbtn" TYPE="text" NAME="#Title#" id="#title#" VALUE=" &nbsp; " SIZE="4" MAXLENGTH="4">
   </td>
  </tr>
 </table>
</cfoutput>
</div>
</body>
</html>
                     

complete.cfm - you update goes here do whatever u want to do and return anything whatever message u wanna display to user, and div will reload
0
 

Author Comment

by:Qsorb
ID: 37726611
DaveBaldwin: I had seen that earlier and it may be far beyond my ability.

myselfrandhawa: Looks interesting but some of your suggestions are confusing to me:

You wrote:  "complete.cfm - you update goes here do whatever u want to do and return anything whatever message u wanna display to user, and div will reload"

Where does "complete.cfm", or in my case, "update.cfm" go? You seem to indicate it goes on the same page, or do you mean to cfinclude it?  And if so, under what condition?  I don't have a clue as to what you mean,  as to where the cfquery update actually goes, and how, and even when.

Also not sure of this:

<div is="message"></div>
<div id="refreshMe">

Did you mean <div id="message"></div>     (I changed your "is" to "id")? Is that correct, id instead of is?

And what does the refreshMe id do,  for what?

And just as important, you suggested, "why not use jquery here like this:"

I included that Javascript on the same page, between HEAD with <script type="text/javascript">. Not sure if this is what you meant.

Did you mean to also include a jquery code somewhere? This is also confusing. You may be thinking I know what you mean, when I  don't. You took some time to explain, and I appreciate it, but what I wrote above is most of what I don't understand.

Please clarify soon as you can as I URGENTLY need this. Thanks!
0
 

Author Closing Comment

by:Qsorb
ID: 37727101
Fortunately, I was able to get this working using  Ajax so will just close this and award points evenly.

I used the info on this page which gave me a working example. I had to modify my code quite a bit of course, to get it working, but this demo was the key to get my example working:

http://www.coldfusionjedi.com/demos/sharp/ajaxSubmit/
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question