Bonjour,
je cherche a adapter un script "d'autocomplete" pour pouvoir passer l'id du champ de saisie en parametre, et ainsi pour appel ce script plusieurs fois dans une page.

Voila les fonctions pour les suggestions:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
 
var ajaxObj = getAjaxObject();
 
function autoSuggest(id,qtype)
{
   var searchInput = getElemId(id).value;
 
   var url = "modules/Samples/autosuggest.php";
   var params = "input=" + searchInput + "&qtype="+ qtype;
 
   if (trim(searchInput) !== "")
   {
	  sendRequest(ajaxObj, url, params, handleSuggestResponse(id));
   }
   else
   {
	  hideSuggestions();   
   }
}
 
function handleSuggestResponse(id)
{
   if (ajaxObj.readyState == 4)
   {
      if (ajaxObj.status == 200)
      {
		  try
		  {
			  var XMLResponse = ajaxObj.responseXML.documentElement;
			  // work with the xml response
			  var keywordsTag = XMLResponse.getElementsByTagName('keywords');
 
			  var suggestions = new Array();
 
			  for (var i = 0; i < keywordsTag.length; i++)
			  {
				 var keywords = keywordsTag.item(i).firstChild.data.toString();
				 suggestions.push(keywords);
			  }
			  showSuggestions(suggestions);
		  }
		  catch(e)
		  {
			  hideSuggestions();
			  if (trim(ajaxObj.responseText) !== "")
			  alert(ajaxObj.responseText);  
		  }
	  }
   }
}
 
function showSuggestions(suggestions)
{
   var listWrapID = getElemId("listWrap");
   listWrapID.style.visibility = "visible";
 
   var listID = getElemId("searchList");
   listID.innerHTML = "";
 
   for(var i = 0; i < suggestions.length; i++)
   {
     listID.innerHTML += "<li><a href=\"javascript:void(0);\" onclick=\"insertKeyword(this.innerHTML);\">" + suggestions[i] + "</a></li>";      
   }     
}
 
 
function hideSuggestions()
{
   var listWrapID = getElemId("listWrap");
   listWrapID.style.visibility = "hidden";	
}
 
function insertKeyword(str)
{
	getElemId("input").value = str;
	hideSuggestions();
}
et le coté ajax
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
Ajax Library:
===========
This library contains all the code you need to initiate the xmlHTTPObject
and the general procedure of sending ajax request to the server and
receiving it.
@version: 1.0
@author:  Waseem Khan
@blog:    http://blog.pakcoders.com
*/
 
function getAjaxObject()
{
  // initially set the object to false 
  var XMLHttpRequestObject = false;
  if (window.XMLHttpRequest)
  {
      // check for Safari, Mozilla, Opera...
	  XMLHttpRequestObject = new XMLHttpRequest();
  }
  else if (window.ActiveXObject) 
  {
      // check for Internet Explorer
	  XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
  }
  if (!XMLHttpRequestObject)
  {
	  alert("Your browser does not support Ajax.");
	  // return false in case of failure
	  return false;
  }
  // return the object in case of success
  return XMLHttpRequestObject;
}
 
 
function sendRequest(xmlHTTPObject, url, parameters, handleResponse)
{
   if(xmlHTTPObject)
   {
      // continue if the object is idle
      if (xmlHTTPObject.readyState == 4 || xmlHTTPObject.readyState == 0) 
      {
		 // open connection and send "GET" request to server
		 xmlHTTPObject.open("POST", url, true);
		 // send the appropriate headers
		 xmlHTTPObject.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		 // set the function to be called on a change in ajaxObj state
		 xmlHTTPObject.onreadystatechange = handleResponse;
		 // set additional parameters (to be sent to server) to null
         xmlHTTPObject.send(parameters);
      }
   }
}
j'ai ajouté un parametre id a la fonction autoSuggest, puis a la fonction handleSuggestResponse(id), mais a ce moment la, j'obtiens l'erreur:
non implementé
sendRequest(ajaxObj, url, params, handleSuggestResponse(id));

Je ne comprensd pas ce qui cloche. D'un autre coté, je suis bloqué aussi pour trimbaler ma variable id jusqu'a la fonction insertKeyword ...

Un peu de lumiere me ferait du bien!!

A+
VooDoo