Autoload dropview from another dropview with jQuery

Topics: User Forum
Feb 19, 2016 at 10:53 AM
Hi all!
I want to load a dropview content from a query based on another dropview.

I use this jQuery code:
    <script type="text/javascript">
        $(document).ready(function(){
            var scegli = '<option value="0">Scegli...</option>';
            var attendere = '<option value="0">Attendere...</option>';
            
            $("select#province").html(scegli);
            $("select#province").attr("disabled", "disabled");
                    
            $("select#regioni").change(function(){
                var regione = $("select#regioni option:selected").attr('value');
                $("select#province").html(attendere);
                $("select#province").attr("disabled", "disabled");
                $("select#comuni").html(scegli);
                $("select#comuni").attr("disabled", "disabled");
                
                $.post("test.avfp", {reg:regione}, function(data){
                    $("select#province").removeAttr("disabled"); 
                    $("select#province").html(data);    
                });
            }); 
        });
    </script>
In php, i use this post method: $.post("test.php", {reg:regione}, function(data){ to call a webpage that have this code:
if(isset($_POST['id_reg']))
{
    echo "blablabla..."
    die;
}
In this case, the "die" instruction close the operation and return me only the content of echo to my main page.
How can i do this in avfp ? I'll tryed but not work...

Any idea?
Feb 20, 2016 at 12:22 AM
Try this (AVFP+):
IF AVIsSet("id_ref")
 AVEcho("blablabla..."
 RETURN
ENDIF
Victor
Feb 23, 2016 at 4:44 PM
Uhm... not work. I think that my AVFP version (this project have the standard) not include AVEcho.
Feb 24, 2016 at 8:46 AM
mr_ocean wrote:
Uhm... not work. I think that my AVFP version (this project have the standard) not include AVEcho.
Ok. I added AVEcho function that i found on the forum. However not work. AVEcho works but the combo not updated.
Feb 29, 2016 at 5:28 PM
IsSet() and AVEcho() are part of the AVFP extension pack and would be included in the next major release of AVFP.

Victor
Feb 29, 2016 at 5:32 PM
For what is worth, this is a slight stripped version of the AVEcho() and AVEchoLN() functions:
* AVEcho
* PHP ECHO implementation. Allows to inject markup in
* response HTML from inside server side code.
*
* Examples:
* AVEcho("this goes to the <b>html</b> response")
* AVEcho("this goes in one line \br and this in another")
* AVEcho(.T.) --> true
*
* 
FUNCTION AVEcho(puValue)
 IF VARTYPE(strVar)<>"C"
  RETURN
 ENDIF
 IF PCOUNT() = 0 
  puValue = ""
 ENDIF
 
 LOCAL cType,cStr
 cType = VARTYPE(puValue)
 cStr = ""
 
 TRY
     DO CASE
        CASE cType = "C"
             cStr = ALLTRIM(puValue)
             cStr = STRT(cStr, "\n", CHR(13)+CHR(10))
             cStr = STRT(cStr, "\br", "<BR/>")
                         
        CASE cType = "X"
             cStr = "null"
       
        CASE cType = "N" AND INT(puValue) = puValue
             cStr = ALLTRIM(STR(puValue))
                        
        CASE cType = "L"
             cStr = IIF(puValue, "true", "false")
             
        OTHERWISE
             cStr = TRANSFORM(puValue, "")
     ENDCASE
     
 CATCH TO ex
     cStr = "<i>" + ex.Message + "</i>"
 
 ENDTRY
 
 strVar = strVar + cStr
ENDFUNC
FUNCTION AVECHOLN(puValue, pcFormat)
 IF PCOUNT() = 0 
  puValue = ""
 ENDIF
 AVECHO(puValue)
 strVar = strVar + "<br>"
ENDFUNC
Mar 1, 2016 at 8:55 AM
This is the code that i found on the forum. In this time, i've not solved my problem but i changed the method. I put a single select (combobox) with all data grouped thanks to this free HTML component for Bootstrap (http://select2.github.io/).

Isn't faster but works fine!