Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loop over CF ValueList in ColdFusion

Status
Not open for further replies.

rockyroad

Programmer
Feb 22, 2003
191
US
Hi,

I have the following javascript:

Code:
<script type="text/javascript">
    function show() {
      if((document.myForm.Category.options[document.myForm.Category.selectedIndex].value == '13') || (document.myForm.Category.options[document.myForm.Category.selectedIndex].value == '14' ) || (document.myForm.Category.options[document.myForm.Category.selectedIndex].value == '15') || (document.myForm.Category.options[document.myForm.Category.selectedIndex].value == '16')){
        document.getElementById('ShowSizes').style.display='block';
    }
      else
        {document.getElementById('ShowSizes').style.display='none';}
    }
</script>

Which executes nicely. What i'd like to do is remove the hardcoded "||" statements and "== '15'" statements and instead loop through a ValueList that I have set from a query. Any advice on how to pass the CF ValueList to javascript and loop accordingly?

This loop returns the same variables hard coded in the javascript above:

<cfloop index = "category_ID" list = "#TheList#" delimiters = ",">
<cfoutput>#category_ID#</cfoutput><br>
</cfloop>

Thanks!

RR
 
This should work...
If you select a value not in "TheList" (17 or 18) it will hide the ID else it will show the ID.

<cfset request.TheList = '13,14,15,16'>
<script type="text/javascript">
function show(){
var stringToSplit = '<cfoutput>#request.TheList#</cfoutput>';
var arrayOfStrings = stringToSplit.split(",");
var count=0;
var isFound=false;
while (count < arrayOfStrings.length)
{
if(document.myForm.Category.options[document.myForm.Category.selectedIndex].value == arrayOfStrings[count]){
isFound=true;
}
count+=1;
}
if (isFound){
document.getElementById('ShowSizes').style.display='block';
}
else{
document.getElementById('ShowSizes').style.display='none';
}
return arrayOfStrings[0];
}
</script>
<form name="myForm" action="" method="post">
<select name="Category" onchange="show()">
<cfoutput>
<cfloop index = "category_ID" list = "#request.TheList#" delimiters = ",">
<option value="#category_ID#">#category_ID#</option>
</cfloop>
</cfoutput>
<option value="17">17</option>
<option value="18">18</option>
</select>
<div id="ShowSizes">
a div to hide based on category.
</div>
</form>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top