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

LVL 2
PanosAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Azadi
0
PanosAuthor Commented:
wait a moment.i will try to do this
0
PanosAuthor Commented:
Try here
http://carbay.selfip.com/test/test.cfm
i will let it work until you can fix it.
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

azadisaryevCommented:
thanks, looking at it now...

first, let correct a js error you have to get it out of the way:

in your defaultselect2 function change dd to dd2 in this line:
dd.options[i].selected = true;


also, can you please add this line:

console.log(valarray);

after var valarray=val.split(','); line in each of your 3 functions (and re-upload the changed page).

Azadi
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
azadisaryevCommented:
also, change bindonload attribute to "false" in your second cfselect, and add bindonload="false" to the third one.

Azadi
0
azadisaryevCommented:
yep, juts re-tested it:

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

Azadi
0
PanosAuthor Commented:
OK
take a look now
0
PanosAuthor Commented:
That's it azadi.

Thank you again...
0
PanosAuthor Commented:
Thank you azadi for your help
regards
panos
0
azadisaryevCommented:
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.