CodeCharge Studio
search Register Login  

Web Reports

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

YesSoftware Forums -> CodeCharge Studio -> General/Other

 Another dependent dropdown question

Print topic Send  topic

Author Message
robn

Posts: 70
Posted: 11/25/2005, 9:10 AM

Right I know there are loads of topics on this but I have search through most of them and can't find the solution to my issue. i have build a dependent listbox based on some of the examples out there (mainly the one in the CCS example pack 2) which works perfectly apart from one thing. I can get the first list box to populate the second list box fine (based on the selection from the first list box). But the issue I have is that some of the fields in the second list box (in this case a status dropdown) should appear in all the selections from the first (Category) list box (i.e. some of the status fields are generic and cover all categories). I know I could get around this by creating the same status for all the categories. But what I would like to do is say show all Statuses associated with category X plus all statuses with a category value of 0.

My code so far looks like this

<script language="JavaScript">
var DomYes=document.getElementById?1:0;

function set_child_listbox(parentObject,childObject,childArray,spanToHide) {

//Clear child listbox
for(var i=childObject.length;i>0;i--) {
childObject.options = null;
}

childObject.options[0] = new Option("Select Value","");
var sel_index = parentObject.options[parentObject.selectedIndex].value;
if (sel_index == "") {
childObject.disabled = true;
} else {
childObject.disabled = false;
var childIndex = 1;
for (i = 0; i < childArray.length; i++) {
if (childArray[1] == sel_index) {
childObject.options[childIndex] = new Option(childArray[2], childArray[0]);
childIndex++;
}
}
}
//Select first option
childObject.selectedIndex = 0;


}

function reload_page() {
var sel_index = document.tblQualcall.s_Category_id.options[document.tblQualcall.s_Category_id.selectedIndex].value;
var sel_subindex = document.tblQualcall.s_status.options[document.tblQualcall.s_status.selectedIndex].value;
if (sel_subindex != "") {
document.location.href = document.location.pathname + "?" + "s_status=" + sel_subindex+"&s_Category_id=" + sel_index;
}
}

function disable_child_listbox(spanToHide) {

//Disable second listbox
if (document.tblQualcall.s_Category_id.selectedIndex == "") {
document.tblQualcall.s_status.disabled = true;
}

}

window.onload = function() {
disable_child_listbox("Products");
}

<!-- BEGIN Grid tblQualCategory_tblQualst -->
var Status = new Array(
<!-- BEGIN Row -->
new Array({tblStatus_Id},{tblStatus_CategoryLink},'{tblStatus_Status}')<!-- END Row --><!-- BEGIN Separator -->,<!-- END Separator -->
);
<!-- END Grid tblQualCategory_tblQualst -->
</script>

hope this makes sense any help would be much appriciated.

thanks

Rob
View profile  Send private message
matheus

Posts: 386
Posted: 11/25/2005, 11:20 AM

Do something like this.

Another grid (array in javascript) with all "generic" options.

Always populate the second listbox with genericStatus and then with your Status from category.

The only problem was the order.

Sorry my english.
_________________
Matheus Trevizan

Dynamix Software Ltda.
Blumenau SC Brasil
www.dynamix.com.br
View profile  Send private message
robn

Posts: 70
Posted: 11/28/2005, 2:59 AM

Thanks Matheus

I'm not quite sure how that helps though as currently I have an onchange event on the first drop down that does the following.

<select onchange="set_child_listbox(this, document.tblQualcall.s_status,Status,'Products');" name="{s_Category_id_Name}">

Which I presume just passes the first grid values. I thought there may be a way of adding to this onchange event to include the generic values but am unsure of how to do this?

Rob
View profile  Send private message
matheus

Posts: 386
Posted: 11/28/2005, 5:29 AM

In method set_child_listbox assume that Products and generic array must be added in listbox.

Something like this (not tested):

  
function set_child_listbox(parentObject,childObject,childArray,spanToHide) {  
  
	//Clear child listbox  
	for(var i=childObject.length;i>0;i--) {  
		childObject.options = null;  
	}  
  
	childObject.options[0] = new Option("Select Value","");  
	var sel_index = parentObject.options[parentObject.selectedIndex].value;  
	if (sel_index == "") {  
		childObject.disabled = true;  
	} else {  
		childObject.disabled = false;  
		var childIndex = 1;  
                 
		for (i = 0; i < genericArray.length; i++){  
		    childObject.options[childIndex] = new Option(genericArray[2], genericArray[0]);  
		    childIndex++;  
		}  
                 
		for (i = 0; i < childArray.length; i++) {  
			if (childArray[1] == sel_index) {  
				childObject.options[childIndex] = new Option(childArray[2], childArray[0]);  
				childIndex++;  
			}  
		}  
	}  
	//Select first option  
	childObject.selectedIndex = 0;  
}  

Just a new for in set_child_listbox adding generic array.
_________________
Matheus Trevizan

Dynamix Software Ltda.
Blumenau SC Brasil
www.dynamix.com.br
View profile  Send private message
robn

Posts: 70
Posted: 11/28/2005, 7:52 AM

Thanks Matheus your code helped me find the resolve your idea was very close the final code that works looks like this

function set_child_listbox(parentObject,childObject,childArray,genericArray,spanToHide) {  
  
        //Clear child listbox  
        for(var i=childObject.length;i>0;i--) {  
                childObject.options = null;  
        }   
          
        childObject.options[0] = new Option("Select Value","");  
        var sel_index = parentObject.options[parentObject.selectedIndex].value;  
        if (sel_index == "") {  
                childObject.disabled = true;  
        } else {  
                childObject.disabled = false;  
                var childIndex = 1;  
				for (i = 0; i < genericArray.length; i++){  
						if (genericArray[1] == 0) {    
		    				childObject.options[childIndex] = new Option(genericArray[2], genericArray[0]);    
		    				childIndex++;    
		}    
                   
}  
                for (i = 0; i < childArray.length; i++) {  
                        if (childArray[1] == sel_index) {  
                                childObject.options[childIndex] = new Option(childArray[2], childArray[0]);  
                                childIndex++;  
                        }  
                }  
        }  
        //Select first option  
        childObject.selectedIndex = 0;{

the only minor change I had to make was to set an if (genericArray[1] == 0) { filter and it works fine

thanks again

Rob
View profile  Send private message
robn

Posts: 70
Posted: 11/28/2005, 10:08 AM

Hello

Right I have also discovered something else with the code. When I use the functionality to view a current record the current status was set to the correct value but I was able to choose any status (i.e. not just the ones associated with the category), So I tried to be clever and created a window.onload event which basically consisted of the same code used in the onchange event (see previous post). Which works fine and only displays the Statuses associated with the selected category. But the one thing that it does change is instead of holding the current value in the Status listbox it resets it to "Select Value". I've tried removing the "clear child list box code" which then displayed all the Statuses again. Also I have tried tweaking the childObject.options[0] = code with little success.

What I need to be able to do is display the current value along with all the values associated with the current category.

Any help would be much appreciated.

Thanks in advance,

Rob
View profile  Send private message
matheus

Posts: 386
Posted: 11/28/2005, 11:13 AM

Look...

I do something like this.

In window.onload custom code created:

Before all, retrieve selectedIndex from second listbox.

Then set_child_listbox normally

And after, set second listbox again with selectedIndex retrieved.

With generic array could had some problems, need take a look.

  
var cmp = document.forms['frm'].cd_sub_category;  
var selectedID = cmp.options[cmp.selectedIndex].value;  
set_child_listbox(document.forms['frm'].cd_category, cmp,Product);  
cmp.value = selectedID;  

Something like this... in javascript
_________________
Matheus Trevizan

Dynamix Software Ltda.
Blumenau SC Brasil
www.dynamix.com.br
View profile  Send private message
matheus

Posts: 386
Posted: 11/28/2005, 11:20 AM

In before show not retrieve selectedIndex from second listbox, recover value.

var selectedID = cmp.options[cmp.selectedIndex].value;

Because, the value is going to be in second listbox and didn't know the selectedIndex after...

Sorry my english.
_________________
Matheus Trevizan

Dynamix Software Ltda.
Blumenau SC Brasil
www.dynamix.com.br
View profile  Send private message
robn

Posts: 70
Posted: 11/30/2005, 9:30 AM

matheus

Many thanks for all your help it appears to be working great

thanks again

Rob
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.

MS Access to Web

Convert MS Access to Web.
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.