473,386 Members | 1,796 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,386 software developers and data experts.

Ajax dynamic list, show full textfield string value on save

162 100+
Hello fellow code junkies,

I am using the "Ajax dynamic list" http://dhtmlgoodies.com/index.html?w...x-dynamic-list and i think its the best out there. I have found a compatibility issue maybe one of you can help me out on.

In this html i use a text field to collect info. when a user types, *ajax_showOptions()* shows the option perfectly. once an item is selected and i move from the field, *makeRequest()*, my set variable to database php page is triggered and it saves to the database properly. my problem is that the value saved to the database is only the first few charaters *ajax_showOptions()* used to fill the dropdown. Example, if i type, *ce* the dropdown show *cesar*, i choose *cesar* and the database sets *ce*.

So my question is how do i get the database to set the full value in the textfield. How do i get *this.value* in makeRequest() to be the full value. Thanks.

Here is my html.

Expand|Select|Wrap|Line Numbers
  1. <input onkeyup="ajax_showOptions(this,'company_name',event)" type="text" id="company_name" name="company_name" value='' onblur="javascript:makeRequest('ajax_edit_company.php?valu=',this.value);">
  2.  

The *ajax_showOptions()* script is unchanged from link above. Here is the *makeRequest()* script. This script is working great as is, besides possibly the current issue.
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript" language="javascript">
  2.    var http_request = false;
  3.    function makeRequest(url, parameters) {
  4.       http_request = false;
  5.       if (window.XMLHttpRequest) { // Mozilla, Safari,...
  6.          http_request = new XMLHttpRequest();
  7.          if (http_request.overrideMimeType) {
  8.              // set type accordingly to anticipated content type
  9.             //http_request.overrideMimeType('text/xml');
  10.             http_request.overrideMimeType('text/html');
  11.          }
  12.       } else if (window.ActiveXObject) { // IE
  13.          try {
  14.             http_request = new ActiveXObject("Msxml2.XMLHTTP");
  15.          } catch (e) {
  16.             try {
  17.                http_request = new ActiveXObject("Microsoft.XMLHTTP");
  18.             } catch (e) {}
  19.          }
  20.       }
  21.       if (!http_request) {
  22.          alert('Cannot create XMLHTTP instance');
  23.          return false;
  24.       }
  25.       http_request.onreadystatechange = alertContents;
  26.       http_request.open('GET', url + parameters, true);
  27.       http_request.send(null);
  28.    }
  29.  
  30.    function alertContents() {
  31.       if (http_request.readyState == 4) {
  32.          if (http_request.status == 200) {
  33.             //alert(http_request.responseText);
  34.             result = http_request.responseText;
  35.             document.getElementById('myspan').innerHTML = result;
  36.          } else {
  37.             alert('There was a problem with the request.');
  38.          }
  39.       }
  40.    }
  41.  
  42.    function get(obj) {
  43.       var getstr = "?";
  44.       for (i=0; i<obj.childNodes.length; i++) {
  45.          if (obj.childNodes[i].tagName == "INPUT") {
  46.             if (obj.childNodes[i].type == "text") {
  47.                getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
  48.             }
  49.             if (obj.childNodes[i].type == "checkbox") {
  50.                if (obj.childNodes[i].checked) {
  51.                   getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
  52.                } else {
  53.                   getstr += obj.childNodes[i].name + "=&";
  54.                }
  55.             }
  56.             if (obj.childNodes[i].type == "radio") {
  57.                if (obj.childNodes[i].checked) {
  58.                   getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
  59.                }
  60.             }
  61.          }
  62.          if (obj.childNodes[i].tagName == "SELECT") {
  63.             var sel = obj.childNodes[i];
  64.             getstr += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";
  65.          }
  66.  
  67.             if (obj.childNodes[i].type == "textarea") {
  68.                getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
  69.             }
  70.  
  71.       }
  72.       makeRequest('get.php', getstr);
  73.    }
  74. </script>
  75.  
Feb 28 '07 #1
1 2864
acoder
16,027 Expert Mod 8TB
Are you using onblur for the request to the database? It is unreliable. It may be that the text box loses focus before the value is set.
Mar 1 '07 #2

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

Similar topics

7
by: Jack | last post by:
Hi, I am trying to test a sql statement in Access which gives me the error as stated in the heading. The sql statement is built as a part of asp login verification, where the userid and password...
1
by: Nathan Bloomfield | last post by:
Does anyone know if there is any documentation which relates to Access2k + ? or can anyone help adjust the code? I am having trouble converting the DAO references. TITLE :INF: How to...
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
2
by: brakai295 | last post by:
Hi there, I need someone to customise an autocompletion AJAX script a little bit. This free script here (demo | info & download) offers you auto-completion when typing in a country's name. I...
4
by: Rob Meade | last post by:
Hi all, I played with my first bit of AJAX the other week and was pleasantly surprised that I achieved my goal..now I'd like to try something else.. Question... If I have an updatePanel,...
1
by: Bob | last post by:
Hi, Hope you can help me with this one. I'm at my wits end. I'm trying to create an intelligent edit-box like the excellent "Customer" one at the URL: ...
13
by: adam | last post by:
Hey All, I'm relatively new to all this and any help would be appreciated. What I'm aiming to do is create a few requests, to 1. Search for a Student against XML created from the database 2. If...
0
by: mix01 | last post by:
Hi, I am trying to get some VBA code working, but am preplex as to why it does not work. I would really appreciate any level of help. Many thanks, Mix01 Version of the program
1
by: Sundhas | last post by:
Hey! I am working on jrxml to create dynamic re0ports. I have parameterized the columns i.e. the jrxml for that report can be used to generate other reports as well. However, i have not managed...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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.