Link to home
Start Free TrialLog in
Avatar of Panos
PanosFlag for Germany

asked on

Coldfusion default values for 3 related selects

Hello experts.
I can't get the default values for my second and third selects in the code below.
Any help?
<cfscript>
mainvalue = ''; 
sub1value = '';
sub2value = '';
vlangid =1;
</cfscript>
<cfparam name="FORM.Country_ID" default="110">
<cfparam name="FORM.CountrySub1_ID" default="740">
<cfparam name="FORM.CountrySub2_ID" default="5845">
<cfif IsDefined("FORM.Country_ID")>
	<cfset mainvalue = #FORM.Country_ID#>
</cfif>
<cfif IsDefined("FORM.CountrySub1_ID")>
	<cfset sub1value = '#FORM.CountrySub1_ID#'>
</cfif>
<cfif IsDefined("FORM.CountrySub2_ID")>
	<cfset sub2value = '#FORM.CountrySub2_ID#'>
</cfif>
<script type="text/javascript">
var place = false;
var place1 = false;
var place2 = false;
function defaultselect(x,val) {
 if (!place && val!=undefined) {
		var valarray=val.split(',');
		var dd = document.getElementById('Country_ID');
		for (var i = 0; i < dd.length; i++) {
			for (var ax=0; ax < valarray.length; ax++) {
				if (dd.options[i].value == parseInt(valarray[ax])) {
					dd.options[i].selected = true;
				}
			}
		}
	}
	place = true;
}

function defaultselect1(x,val) {
 if (!place1 && val!=undefined) {
		var valarray=val.split(',');
		var dd1 = document.getElementById('CountrySub1_ID');
		for (var i = 0; i < dd1.length; i++) {
			for (var ax=0; ax < valarray.length; ax++) {
				if (dd1.options[i].value == parseInt(valarray[ax])) {
					dd1.options[i].selected = true;
				}
			}
		}
	}
	place1 = true;
}
function defaultselect2(x,val) {
 if (!place2 && val!=undefined) {
		var valarray=val.split(',');
		var dd2 = document.getElementById('CountrySub2_ID');
		for (var i = 0; i < dd2.length; i++) {
			for (var ax=0; ax < valarray.length; ax++) {
				if (dd2.options[i].value == parseInt(valarray[ax])) {
					dd2.options[i].selected = true;
				}
			}
		}
	}
	place2 = true;
}
</script>
<cfajaxproxy bind="javascript:defaultselect({Country_ID},#mainvalue#)">
<cfajaxproxy bind="javascript:defaultselect1({CountrySub1_ID},'#sub1value#')">
<cfajaxproxy bind="javascript:defaultselect2({CountrySub2_ID},'#sub2value#')">

<cfform>
<cfselect name="Country_ID"
          id="Country_ID"
          bind="cfc:tests.com.test.getMain(#vlangid#)"
          bindonload="true"
          value="Country_ID"
          display="Country_Text" 
          multiple="no"
          />
<cfselect name="CountrySub1_ID"
           id="CountrySub1_ID"
           display="CountrySub1_Text"
           value="CountrySub1_Id" 
           BindOnLoad="true"
           bind="cfc:tests.com.test.getSub1({Country_ID},#vlangid#)"
           />
<cfselect name="CountrySub2_ID"
          id="CountrySub2_ID"
          bind="cfc:tests.com.test.getSub2({CountrySub1_ID},#vlangid#)"
          display="CountrySub2_Text" 
          value="CountrySub2_ID"
          /> 
</cfform>

Open in new window

Avatar of azadisaryev
azadisaryev
Flag of Hong Kong image

can you make this into a test page and make the page web-accessible?
it will be easier to debug it then.

Azadi
Avatar of Panos

ASKER

wait a moment.i will try to do this
Avatar of Panos

ASKER

Try here
http://carbay.selfip.com/test/test.cfm
i will let it work until you can fix it.
ASKER CERTIFIED SOLUTION
Avatar of azadisaryev
azadisaryev
Flag of Hong Kong image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
yep, juts re-tested it:

bindonload MUST be set to "false" in the 2 dependent cfselects for pre-selecting default values to work.

Azadi
Avatar of Panos

ASKER

OK
take a look now
Avatar of Panos

ASKER

That's it azadi.

Thank you again...
Avatar of Panos

ASKER

Thank you azadi for your help
regards
panos
you are welcome :)

just to explain why bindonload must be set to 'false' in dependent cfselects:

if it is set to 'true', or if you do not set it at all (which makes cf assume the default value of 'true'), then the bindings you specified in the <cfselect>s' BIND attribute will fire off, refreshing the cfselects. but these bindings will fire AFTER your js bindings, and will thus 'overwrite' the <option>s - inclusing the pre-selected one - which were set by the js bindings.

Azadi