473,387 Members | 1,572 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

ajax xmlhttprequest

Hello,

I am trying to fix a web/database problem (someone else wrote) and am not that familiar with Java or Ajax.

The code opens a list when data is typed in a text input field but the "onkeyup" selection is not what is written to the database.

For example: I type "Ma" in a text box. A list of names appears: "Maggie", "Margaret", "Mary". I click on "Mary" to select it and submit the page. When I check the data input in the database, "Ma" is what was input.

The code looks like this:
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>User Select</title>
  4. <script language="JavaScript" type="text/javascript" src="ajax.js"></script>
  5. </head>
  6.  
  7. <form action="user_save.cfm  method="post" enablecab="yes">
  8. <table>
  9. <tr><td>
  10. Names: <br>
  11. <input type="text" name="names_search" size="10" onKeyUp="xmlhttpRequest('ajax_get_names.cfm', this.value, 'names')" ><br>
  12. <div id="names"></div>
  13. </td></tr></table>
The user_save.cfm code :

Expand|Select|Wrap|Line Numbers
  1. <cfoutput>
  2. <cfif not isdefined("form.names_search")><cflocation url=""></cfif><br>
  3. </cfoutput>
  4.  
  5. <cfquery name="user_save" datasource="#ds#">
  6. insert into dbspace.team_member
  7. ( member)
  8. value
  9. (
  10.     <cfqueryparam value = "#names_search#" cfsqltype="cf_sql_varchar">
  11. )
  12. </cfquery>
The ajax_get_names.cfm is a <cfquery> to a person table with <select><cfoutput> to get the list of names form the table.

Does anyone have any ideas?
Mar 23 '10 #1
3 2045
You didn't post the source code for ajax.js. In the meanwhile, did you try it in different browsers? Try also not having it in a table. Also, how's about giving the input an id and using that instead of this.value. I've found that the 'this' keyword can make trouble sometimes in some browsers. Good luck.
Mar 24 '10 #2
I tried in a different browser with the same results. Giving the input an id and changing "this.value" to that id resulted in no names populating the selection box.

Here is the ajax.js src code:

Expand|Select|Wrap|Line Numbers
  1. function xmlhttpRequest(strURL,strInput,strOutput) {
  2.  
  3.     var xmlHttpReq = false;
  4.     var self = this;
  5.     // Mozilla/Safari
  6.     if (window.XMLHttpRequest) {
  7.         self.xmlHttpReq = new XMLHttpRequest();
  8.     }
  9.     // IE
  10.     else if (window.ActiveXObject) {
  11.         self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
  12.     }
  13.     // open js window to get data
  14.     self.xmlHttpReq.open('POST', strURL, true);
  15.     self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  16.     self.xmlHttpReq.onreadystatechange = function() {
  17.         if (self.xmlHttpReq.readyState == 4) {
  18.             // update the page with the data from the called page
  19.             updatepage(self.xmlHttpReq.responseText,strOutput);
  20.         }
  21.     }
  22.     // make call to page to get data
  23.     self.xmlHttpReq.send(getquerystring(strInput));
  24. }
  25. // page to call
  26. function getquerystring(strInput) {
  27.     qstr = 'i=' + escape(strInput);  // NOTE: no '?' before querystring
  28.     return qstr;
  29. }
  30. //sends the new data to the page
  31. function updatepage(str,strOutput){
  32.     if(str.length > 10) {
  33.         // replace data on page with this new data
  34.         document.getElementById(strOutput).innerHTML = str;
  35.     }
  36. }

Thanks for your help.
Mar 24 '10 #3
There is nothing there to put the results into input's value. It only puts it into the DIV that you specified, 'names'.
I'd say that you should add to the code, after calling the xmlhttpRequest function, that puts it into the DIV:
;this.value=names.innerHTML
Mar 24 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: bobzimuta | last post by:
I'm creating a simple AJAX library. It's an object that will return an array containing the response text or xml. I'm trying to find a way to assign the response as a property of the object, but...
23
by: ivan | last post by:
AJAX is a stupid and confusing word. People is wondering for something that programmers have used for many years. Javascript + Xml and asynchronous requests is not new. People started to speak...
3
by: Simon | last post by:
I have the following code in Javascript which is creating and sending an XMLHttpRequest . <code> var xmlHttp; /*@cc_on @*/ /*@if (@_jscript_version >= 5) try { xmlHttp = new...
9
by: balakrishnan.dinesh | last post by:
hi frnds, Is Ajax can only used as xmlhttp or else it can use for anyother purpose, If any sample example code for that, plz reply to me soon. Thanks Dinesh B...
1
by: diaboliko80 | last post by:
Salve a tutti. Ho un problema con IE7. Ho implementato una pagina .asp che tramite tecnologia AJAX mi crea una serie di select nidificate (il classico esempio delle Regioni-Province --scelgo...
1
by: geevaa | last post by:
http://www.phpbuilder.com/columns/kassemi20050606.php3 XMLHttpRequest and AJAX for PHP programmers James Kassemi Introduction: Although the concept isn't entirely new, XMLHttpRequest...
0
by: Tarik Monem | last post by:
I have been working on an all AJAX/DOM web site which is set to go live today and I thought I'd share my discoveries with all of you whom have helped me when I have encountered different issues along...
6
by: Bart Van der Donck | last post by:
Hello, I'm presenting my new library 'AJAX Cross Domain' - a javascript extension that allows to perform cross-domain AJAX requests. http://www.ajax-cross-domain.com/ Any comments or...
1
by: bizt | last post by:
Hi, I am having my first real attempt at an ajax class as so far Ive managed to build one that, once instatiated, will allow me to define which function it will call on completion then retrieves...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.