View Complete Thread | FoxWeb Forum Home
Search:
Date:    Msg ID:   
From:    Thread:   
Subject:   
This is how I adapted for my need the sample from Jeff.
The idea is to update a pull down based on selection, the table used for the search is more than a 5000 records in my case so no basic javascript options possible.
You will have to create the table production.dbf  to use the sample.
CREATE TABLE production (client c(100),libelle c(100))
add as many records knowing that the search will be on the client field in this sample I will allow four selection
 
 
 
-------- This is  the regular Html page -------
 
<html>
<meta http-equiv="Content-Language" content="fr">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

 <head>
  <script language="JavaScript">
  <!-- Thank you to Jeff Grippe for the original sample called CheckPW()
  //
  // this FoxWeb AJAX example could not have been developed without having seen the tutorial
  // available at http://www.w3schools.com/ajax/default.asp
  //
  // this is that tutorial re-written for FoxPro / FoxWeb
  //

  var xmlHttp
  function fetchdata()
  {
  // build a variable called url which will call fetchdatavfp.fwx with two query strings
  // the first one is a random value which will always cause the url to reload in the browser
  // the second two are the CLIENT name variables from the from. Only Client is validated
  var url="fetchdatavfp.fwx?"+"sid=" + Math.random() + "&customer=" + document.searchForm.customer.value
 // Setup the xmlHttp object and assign the stateChanged function as the callback function
  xmlHttp=GetXmlHttpObject(stateChanged)
    // Call the url defined above
  xmlHttp.open("GET", url , true)
  xmlHttp.send(null)
  }
  // this function will take the result from the url and put it into the form element
  function stateChanged()
  {
  if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
   {
   document.getElementById(decodeURI("result")).innerHTML=xmlHttp.responseText
   }
  }
  // this function creates and xmlHttp object and assigns the callback function
  function GetXmlHttpObject(handler)
  {
  var objXmlHttp=null
  if (navigator.userAgent.indexOf("Opera")>=0)
   {
   alert("This example doesn't work in Opera")
   return
   }
  if (navigator.userAgent.indexOf("MSIE")>=0)
   {
   var strName="Msxml2.XMLHTTP"
   if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
    {
    strName="Microsoft.XMLHTTP"
    }
   try
    {
    objXmlHttp=new ActiveXObject(strName)
    objXmlHttp.onreadystatechange=handler
    return objXmlHttp
    }
   catch(e)
    {
    alert("Error. Scripting for ActiveX might be disabled")
    return
    }
   }
  if (navigator.userAgent.indexOf("Mozilla")>=0)
   {
   objXmlHttp=new XMLHttpRequest()
   objXmlHttp.onload=handler
   objXmlHttp.onerror=handler
   return objXmlHttp
   }
  }
  // -->
  </script>
 </head>
 
 <body>
This sample is completely based on the password already posted by Jeff Grippe, this is about showing how I used it
once the ajax is done you can send the form to the next form called test1.fwx or whatever you want
  <form name="searchForm" id="searchForm" method="post" action="test1.fwx">
   &nbsp;<br>
   Select a customer
    <select size="1" name="customer" id="customer" onchange="fetchdata()">
    <option>seat</option>
    <option>test</option>
    <option>data 1</option>
    <option>whatever you want this is your customer name</option>
    </select><br>
  <p><span id="result"></span>
  </p>
  </form>
 </body>
</html>
 ------------------------------------
 
 
This is the new program called by Ajax it needs to be called fetchdatavfp.fwx
 
Search Result :
<%
* this is a sample script that is part of an AJAX demonstration
* it gets one query strings from the url and validates the search
* this could have been any Fox code, however.
* the important thing is that the values that are returned are returned using response.write.
* get the parameters
SET DELETED ON
critere = request.querystring("customer") && get the cutomer selected
iF !empty(critere)
use production ORDER libelle  &&your table this mine has one field called client and one called libelle
set filter to allt(lower(critere))$allt(lower(client)) &&filter whatever sounds like the request in the html form client field
datatowrite='<select size="1" name="customerprod" onchange=submit()>'  &&start building my return html code
go top
do while !eof()
datatowrite=datatowrite+'<option>'+allt(libelle)+'</option>'+CHR(10)+CHR(13) &&build the html pull up 
skip
ENDDO
datatowrite=datatowrite+'</select>'

&& This part is a plus in case you deal with special character, this is my case for French this could also be a table
 
datatowrite=STRTRAN(datatowrite,"!","&#33;")
datatowrite=STRTRAN(datatowrite,"_","&#95;")
datatowrite=STRTRAN(datatowrite,"Û","&#219;")
datatowrite=STRTRAN(datatowrite,"®","&reg;")
datatowrite=STRTRAN(datatowrite,"    ","&#34;")
datatowrite=STRTRAN(datatowrite,"`","&#96;")
datatowrite=STRTRAN(datatowrite,"Ü","&#220;")
datatowrite=STRTRAN(datatowrite,"#","&#35;")
datatowrite=STRTRAN(datatowrite,"Ý","&#221;")
datatowrite=STRTRAN(datatowrite,"Þ","&#222;")
datatowrite=STRTRAN(datatowrite,"ß","&#223;")
datatowrite=STRTRAN(datatowrite,"¢","&#162;")
datatowrite=STRTRAN(datatowrite,"à","&#224;")
datatowrite=STRTRAN(datatowrite,"£","&#163;")
datatowrite=STRTRAN(datatowrite,"á","&#225;")
datatowrite=STRTRAN(datatowrite,"¤","&#164;")
datatowrite=STRTRAN(datatowrite,"â","&#226;")
datatowrite=STRTRAN(datatowrite,"¥","&#165;")
datatowrite=STRTRAN(datatowrite,"ã","&#227;")
datatowrite=STRTRAN(datatowrite,"Â","&Acirc;")
datatowrite=STRTRAN(datatowrite,"¦","&#166;")
datatowrite=STRTRAN(datatowrite,"ä","&#228;")
datatowrite=STRTRAN(datatowrite,"Ã","&Atilde;")
datatowrite=STRTRAN(datatowrite,"§","&#167;")
datatowrite=STRTRAN(datatowrite,"å","&#229;")
datatowrite=STRTRAN(datatowrite,"Ä","&Auml;")
datatowrite=STRTRAN(datatowrite,"æ","&#230;")
datatowrite=STRTRAN(datatowrite,"Å","&Aring;")
datatowrite=STRTRAN(datatowrite,"©","&#169;")
datatowrite=STRTRAN(datatowrite,"ç","&#231;")
datatowrite=STRTRAN(datatowrite,"Æ","&AElig;")
datatowrite=STRTRAN(datatowrite,"ª","&#170;")
datatowrite=STRTRAN(datatowrite,"è","&#232;")
datatowrite=STRTRAN(datatowrite,"Ç","&Ccedil;")
datatowrite=STRTRAN(datatowrite,"é","&#233;")
datatowrite=STRTRAN(datatowrite,"È","&Egrave;")
datatowrite=STRTRAN(datatowrite,"¬","&#172;")
datatowrite=STRTRAN(datatowrite,"ê","&#234;")
datatowrite=STRTRAN(datatowrite,"É","&Eacute;")
datatowrite=STRTRAN(datatowrite,"ë","&#235;")
datatowrite=STRTRAN(datatowrite,"Ê","&Ecirc;")
datatowrite=STRTRAN(datatowrite,"®","&#174;")
datatowrite=STRTRAN(datatowrite,"ì","&#236;")
datatowrite=STRTRAN(datatowrite,"Ë","&Euml;")
datatowrite=STRTRAN(datatowrite,"¯","&#175;")
datatowrite=STRTRAN(datatowrite,"í","&#237;")
datatowrite=STRTRAN(datatowrite,"Ì","&Igrave;")
datatowrite=STRTRAN(datatowrite,"°","&#176;")
datatowrite=STRTRAN(datatowrite,"î","&#238;")
datatowrite=STRTRAN(datatowrite,"Í","&Iacute;")
datatowrite=STRTRAN(datatowrite,"±","&#177;")
datatowrite=STRTRAN(datatowrite,"ï","&#239;")
datatowrite=STRTRAN(datatowrite,"Î","&Icirc;")
datatowrite=STRTRAN(datatowrite,"²","&#178;")
datatowrite=STRTRAN(datatowrite,"ð","&#240;")
datatowrite=STRTRAN(datatowrite,"Ï","&Iuml;")
datatowrite=STRTRAN(datatowrite,"³","&#179;")
datatowrite=STRTRAN(datatowrite,"ñ","&#241;")
datatowrite=STRTRAN(datatowrite,"Ð","&ETH;")
datatowrite=STRTRAN(datatowrite,"ò","&#242;")
datatowrite=STRTRAN(datatowrite,"Ñ","&Ntilde;")
datatowrite=STRTRAN(datatowrite,"µ","&#181;")
datatowrite=STRTRAN(datatowrite,"ó","&#243;")
datatowrite=STRTRAN(datatowrite,"Õ","&Otilde;")
datatowrite=STRTRAN(datatowrite,"¶","&#182;")
datatowrite=STRTRAN(datatowrite,"ô","&#244;")
datatowrite=STRTRAN(datatowrite,"Ö","&Ouml;")
datatowrite=STRTRAN(datatowrite,"õ","&#245;")
datatowrite=STRTRAN(datatowrite,"Ø","&Oslash;")
datatowrite=STRTRAN(datatowrite,"ö","&#246;")
datatowrite=STRTRAN(datatowrite,"Ù","&Ugrave;")
datatowrite=STRTRAN(datatowrite,"¹","&#185;")
datatowrite=STRTRAN(datatowrite,"Ú","&Uacute;")
datatowrite=STRTRAN(datatowrite,"º","&#186;")
datatowrite=STRTRAN(datatowrite,"ø","&#248;")
datatowrite=STRTRAN(datatowrite,"Û","&Ucirc;")
datatowrite=STRTRAN(datatowrite,"ù","&#249;")
datatowrite=STRTRAN(datatowrite,"Ü","&Uuml;")
datatowrite=STRTRAN(datatowrite,"@","&#64;")
datatowrite=STRTRAN(datatowrite,"~","&#126;")
datatowrite=STRTRAN(datatowrite,"¼","&#188;")
datatowrite=STRTRAN(datatowrite,"ú","&#250;")
datatowrite=STRTRAN(datatowrite,"Ý","&Yacute;")
datatowrite=STRTRAN(datatowrite,"½","&#189;")
datatowrite=STRTRAN(datatowrite,"û","&#251;")
datatowrite=STRTRAN(datatowrite,"Þ","&THORN;")
datatowrite=STRTRAN(datatowrite,"¾","&#190;")
datatowrite=STRTRAN(datatowrite,"ü","&#252")
datatowrite=STRTRAN(datatowrite,"ß","&szlig;")
datatowrite=STRTRAN(datatowrite,"ý","&#253;")
datatowrite=STRTRAN(datatowrite,"à","&agrave;")
datatowrite=STRTRAN(datatowrite,"À","&#192;")
datatowrite=STRTRAN(datatowrite,"þ","&#254;")
datatowrite=STRTRAN(datatowrite,"á","&aacute;")
datatowrite=STRTRAN(datatowrite,"Á","&#193;")
datatowrite=STRTRAN(datatowrite,"ÿ","&#255;")
datatowrite=STRTRAN(datatowrite,"å","&aring;")
datatowrite=STRTRAN(datatowrite,"Â","&#194;")
datatowrite=STRTRAN(datatowrite,"æ","&aelig;")
datatowrite=STRTRAN(datatowrite,"Ã","&#195;")
datatowrite=STRTRAN(datatowrite,"ç","&ccedil;")
datatowrite=STRTRAN(datatowrite,"Ä","&#196;")
datatowrite=STRTRAN(datatowrite,"è","&egrave;")
datatowrite=STRTRAN(datatowrite,"Å","&#197;")
datatowrite=STRTRAN(datatowrite,"é","&eacute;")
datatowrite=STRTRAN(datatowrite,"Æ","&#198;")
datatowrite=STRTRAN(datatowrite,"ê","&ecirc;")
datatowrite=STRTRAN(datatowrite,"Ç","&#199;")
datatowrite=STRTRAN(datatowrite,"ë","&euml;")
datatowrite=STRTRAN(datatowrite,"È","&#200;")
datatowrite=STRTRAN(datatowrite,"ì","&igrave;")
datatowrite=STRTRAN(datatowrite,"É","&#201;")
datatowrite=STRTRAN(datatowrite,"í","&iacute;")
datatowrite=STRTRAN(datatowrite,"î","&icirc;")
datatowrite=STRTRAN(datatowrite,"Ë","&#203;")
datatowrite=STRTRAN(datatowrite,"ï","&iuml;")
datatowrite=STRTRAN(datatowrite,"Ì","&#204;")
datatowrite=STRTRAN(datatowrite,"ð","&eth;")
datatowrite=STRTRAN(datatowrite,"Í","&#205;")
datatowrite=STRTRAN(datatowrite,"ñ","&ntilde;")
datatowrite=STRTRAN(datatowrite,"Î","&#206;")
datatowrite=STRTRAN(datatowrite,"ò","&ograve;")
datatowrite=STRTRAN(datatowrite,"Ï","&#207;")
datatowrite=STRTRAN(datatowrite,"ó","&oacute;")
datatowrite=STRTRAN(datatowrite,"Ð","&#208;")
datatowrite=STRTRAN(datatowrite,"ô","&ocirc;")
datatowrite=STRTRAN(datatowrite,"Ñ","&#209;")
datatowrite=STRTRAN(datatowrite,"õ","&otilde;")
datatowrite=STRTRAN(datatowrite,"Ò","&#210;")
datatowrite=STRTRAN(datatowrite,"ö","&ouml;")
datatowrite=STRTRAN(datatowrite,"Ó","&#211;")
datatowrite=STRTRAN(datatowrite,"ø","&oslash;")
datatowrite=STRTRAN(datatowrite,"Ô","&#212;")
datatowrite=STRTRAN(datatowrite,"ù","&ugrave;")
datatowrite=STRTRAN(datatowrite,"Õ","&#213;")
datatowrite=STRTRAN(datatowrite,"ú","&uacute;")
datatowrite=STRTRAN(datatowrite,"Ö","&#214;")
datatowrite=STRTRAN(datatowrite,"û","&ucirc;")
datatowrite=STRTRAN(datatowrite,"ý","&yacute;")
datatowrite=STRTRAN(datatowrite,"Ø","&#216;")
datatowrite=STRTRAN(datatowrite,"þ","&thorn;")
datatowrite=STRTRAN(datatowrite,"Ù","&#217;")
datatowrite=STRTRAN(datatowrite,"ÿ","&yuml;")
datatowrite=STRTRAN(datatowrite,"^","&#94;")
datatowrite=STRTRAN(datatowrite,"Ú","&#218;")
response.write(datatowrite)
ELSE
response.write("No match")
ENDIF
%>
ajax request !!

&& thanks a lot to Jeff
 
----------------------- 
 
Then the really basic reply into a form called test1.fwx
 
<html>
<meta http-equiv="Content-Language" content="fr">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 <head>
<%=request.form("customer")%><br>
<%=request.form("customerprod")%>
</body>
</html>