CodeCharge Studio
search Register Login  

Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> ASP

 AJAX -prototype- dependant listboxes default value?

Print topic Send  topic

Author Message
csierra

Posts: 123
Posted: 06/17/2009, 11:33 PM

Hello there, I am having a little annoyance; I have a databound form, with 2 dependant listboxes, and using prototype lib. The thing works just fine; I mean it does filter, when I change the master, proper options (as per data source) are displayed on the child listbox, however, I find that when the form is initially displayed, e.g. update mode, there are values in the subyacent datasource for both boxes, and both boxes show those values accordingly BUT the child listbox is initially not filtered. I have tried to call the AJAX filter routine with another event (Master Listbox OnLoad event) and then, it does filter the child BUT the subyacent datasource value for that box is not displayed (there is nothing selected)

Ive been breaking my head with this for a day now, so Ive added a few lines:

  
// retreive the original value for the child box and keep it ...  
  
	var sender = document.forms.tbSeguimientos.Ciclo_Id;  
	var selval = document.forms.tbSeguimientos.SubCiclo_Id;  
	var thaval = selval.selectedIndex;  
	alert(thaval);  
  
// then I call the AJAX filtering proc  
	tbSeguimientosSubCiclo_IdPTDependentListBox1_start(sender);  
  
// at last, I try to reinstall the original datasource value to the child listbox  
	alert(thaval);				  
	selval.selectedIndex=thaval;  
	selval.refresh;  

It does not work. Somehow, this provoques the child listbox to show empty, no options to select; If I just fire the AJAX thing, it does work (filters) but does not diplay the original child listbox value.

Any comments are kindly appreciated, please ( I hate javascript )

Thank You
_________________
Yes! I Can!!!
View profile  Send private message
Oper


Posts: 1190
Posted: 08/17/2009, 2:52 PM

Did you find any solution simple for this?
_________________
____________________________
http://www.7bz.com (Free CMS,CRM Developed in CCS)

http://www.PremiumWebTemplate.com
Affiliation Web Site Templates

Please do backup first
View profile  Send private message
csierra

Posts: 123
Posted: 08/17/2009, 2:59 PM

Hi Oper, the solution is simply throw to the garbache proto and use jquery.
_________________
Yes! I Can!!!
View profile  Send private message
Oper


Posts: 1190
Posted: 08/17/2009, 4:13 PM

i was thinking the same.
(but if i use jquery the Menu is not working)

but i give a try

no idea why CCS dont doit itself


i just added one line to proto call

if(valueRows[ i ]["0"]==orgslavevalue){dependentElement.options.selectedIndex=i+1;};

for now look like is working
_________________
____________________________
http://www.7bz.com (Free CMS,CRM Developed in CCS)

http://www.PremiumWebTemplate.com
Affiliation Web Site Templates

Please do backup first
View profile  Send private message
csierra

Posts: 123
Posted: 08/25/2009, 10:09 AM

Thanks Oper; where exactly shoud that be added?
_________________
Yes! I Can!!!
View profile  Send private message
Oper


Posts: 1190
Posted: 08/25/2009, 9:30 PM

let me try to explain first cuase the aproach is similiar your try.
But the different is that the listbox dont have value you have to set the Index.


If you want you could change the original function created by CCS
i just avoid that at all cost, to have less pain for CCS 5.0


1)
This one is automaticly create by CCS (this one control the call onCHANGE
  
addEventHandler("Panel1paginadesign_ofjclPDContenidoGrupo", "change", Panel1paginadesign_ofjclPDContenidoPTDependentListBox2_start);

2) now you need to add an event handler (no the same but similiar to avoid change CCS code (use Onload page Client side)
 addEventHandler("Panel1paginadesign_ofjclPDContenidoGrupo", "load", masterbox);


3) I'm no calling same function as you can see i call masterbox function Instead
  
function masterbox(sender)  
{  
//SAVING ORIGINAL VALUE  
var xdependentElement = $("Panel1paginadesign_ofjclPDContenido" + sender.id.substring(40));  
var orgmastervalue=xdependentElement.value  
var x;  
  
  
    var dependentElement = $("Panel1paginadesign_ofjclPDContenido" + sender.id.substring(40));  
    new Ajax.Request("services/CreacionPaginas_paginadesign_ofjcl_PDContenido_PTDependentListBox1.asp?keyword=" + sender.value, {  
        method: "get",  
        requestHeaders: ['If-Modified-Since', new Date(0)],  
        onLoading: function(transport) {  
            for (var i = dependentElement.options.length - 1; i > 0; i--) {  
                var currentOption = dependentElement.options.item(i);   
                if (currentOption.value != "") {  
                    dependentElement.remove(i);  
                }  
            }  
        },  
        onSuccess: function(transport) {  
            var valueRows = eval(transport.responseText.unescapeHTML());  
                          
            for (var i = 0; i < valueRows.length; i++) {  
                var newOption = new Option(valueRows["1"], valueRows["0"]);  
                dependentElement.options[dependentElement.options.length] = newOption;  
// SETTING ORIGINAL VALUE  
                                if(valueRows["0"]==orgmastervalue){dependentElement.options.selectedIndex=i+1;};  
                                  
            }   
        },   
        onFailure: function(transport) {  
            alert(transport.responseText);  
        }   
    });  
  
  
}


NOW THE TRICKY PART
you knwp that teh ID of each listbox in a Grid are Dinamicly create with this format:
Panel1paginadesign_ofjclPDContenidoGrupo_{paginadesign_ofjcl:rowNumber}

The odd number 40 that you see on those function is the lengh in char from the start name of ID to the _ char.


_________________
____________________________
http://www.7bz.com (Free CMS,CRM Developed in CCS)

http://www.PremiumWebTemplate.com
Affiliation Web Site Templates

Please do backup first
View profile  Send private message
efrenlugo


Posts: 9
Posted: 09/23/2009, 12:55 PM

Hello, I try this functions in OnLoad event but don't work for me. With the editable grid.

So I changed 2 lines of the code:

var newOption = new Option(valueRows["1"], valueRows["0"]);

and

if(valueRows["0"]==orgmastervalue){dependentElement.options.selectedIndex=i+1;}; 

So the code look like this:

//Custom Code @167-2A29BDB7  
    // -------------------------  
addEventHandler("WebPage_ComponentsComponentLibraryID", "load", masterbox);  
  
function masterbox(sender)    
{    
var xdependentElement = $("WebPage_ComponentsComponentID" + sender.id.substring(36));    
var orgmastervalue=xdependentElement.value    
var x;    
  
    var dependentElement = $("WebPage_ComponentsComponentID" + sender.id.substring(36));  
    new Ajax.Request("summon_listbox_components.asp?keyword=" + sender.value, {  
        method: "get",  
        requestHeaders: ['If-Modified-Since', new Date(0)],  
        onLoading: function(transport) {  
            for (var i = dependentElement.options.length - 1; i > 0; i--) {  
                var currentOption = dependentElement.options.item(i);  
                if (currentOption.value != "") {  
                    dependentElement.remove(i);  
                }  
            }  
        },  
        onSuccess: function(transport) {  
            var valueRows = eval(transport.responseText);  
            for (var i = 0; i < valueRows.length; i++) {  
                var newOption = new Option(valueRows["1"], valueRows["0"]);  
                dependentElement.options[dependentElement.options.length] = newOption;  
				if(valueRows["0"]==orgmastervalue){dependentElement.options.selectedIndex=i+1;};   
            }   
        },   
        onFailure: function(transport) {  
            alert(transport.responseText);  
        }  
    });  
	  
}  
    // -------------------------  
//End Custom Code  

Information is filtered correctly and the selected value is correct. But some times refreshing the page shows some records with out the child options and nothing selected.

More extrange is that the problem don't occur in Firefox, Safari and IE 6 or 7. Only on IE 8 seems to happen.
_________________
Efren Lugo
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Web Database

Join thousands of Web developers who build Web applications with minimal coding.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright 2003-2004 by UltraApps.com  and YesSoftware, Inc.