469,919 Members | 2,166 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,919 developers. It's quick & easy.

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

Post your reply

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

Similar topics

1 post views Thread by Nathan Bloomfield | last post: by
13 posts views Thread by adam | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.