Highlighted

need to include coldfusion query as dropdown option

Community Beginner ,
Aug 03, 2015

Copy link to clipboard

Copied

<script> function myFunction() { document.getElementById("demo").innerHTML += "<select><option value='1'>option1</option><option value='1'>Option2</option><option value='1'>Option3</option><option value='1'>Option4</option><option value='1'>Option5</option></select>";   var select = document.createElement("select"); //replace this second dropdown with the coldfusion query in below place         var option = document.createElement("option"); option.value = "SubOption1"; option.text = "SubOption"; select.appendChild(option);  document.getElementById("demob").appendChild(select);  return false; } </script>

The above javascript shows dropdown with 5 options, when any of that is selected, the second dropdown shows and list "SubOption1" as the second dropdown options.

My question or where i need further help is, i have a coldfusion query

<cfselect name="NameList" size="1" query="UserRole_q" value="EmpID" display="Name" selected="#temp#"          > <option value="-1"></option> </cfselect> 

which pulls all employee names from the database and list as options.

so, to end my question , i need help placing this coldfusion query to replace the second dropdown ("SubOption1") in the javascript above. thank you for your time

Views

333

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

need to include coldfusion query as dropdown option

Community Beginner ,
Aug 03, 2015

Copy link to clipboard

Copied

<script> function myFunction() { document.getElementById("demo").innerHTML += "<select><option value='1'>option1</option><option value='1'>Option2</option><option value='1'>Option3</option><option value='1'>Option4</option><option value='1'>Option5</option></select>";   var select = document.createElement("select"); //replace this second dropdown with the coldfusion query in below place         var option = document.createElement("option"); option.value = "SubOption1"; option.text = "SubOption"; select.appendChild(option);  document.getElementById("demob").appendChild(select);  return false; } </script>

The above javascript shows dropdown with 5 options, when any of that is selected, the second dropdown shows and list "SubOption1" as the second dropdown options.

My question or where i need further help is, i have a coldfusion query

<cfselect name="NameList" size="1" query="UserRole_q" value="EmpID" display="Name" selected="#temp#"          > <option value="-1"></option> </cfselect> 

which pulls all employee names from the database and list as options.

so, to end my question , i need help placing this coldfusion query to replace the second dropdown ("SubOption1") in the javascript above. thank you for your time

Views

334

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Aug 03, 2015 0
Engaged ,
Aug 04, 2015

Copy link to clipboard

Copied

The forum doesn't seem to be showing your code correctly (runs off the page for me so I can't view it in FF and Chrome).  Any chance you can try to reformat it so we can attempt to answer your question?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 04, 2015 1
Community Beginner ,
Aug 04, 2015

Copy link to clipboard

Copied

<script>

function myFunction()

{ document.getElementById("demo").innerHTML += "<select>

<option value='1'>option1</option>

<option value='1'>Option2</option>

<option value='1'>Option3</option>

<option value='1'>Option4</option>

<option value='1'>Option5</option>

</select>";  

var select = document.createElement("select");

//replace this second dropdown with the coldfusion query in below place        

var option = document.createElement("option");

option.value = "SubOption1";

option.text = "SubOption";

select.appendChild(option); 

document.getElementById("demob").appendChild(select); 

return false;

} </script>

The above javascript shows dropdown with 5 options, when any of that is selected, the second dropdown shows and list "SubOption1" as the second dropdown options.

My question or where i need further help is, i have a coldfusion query

<cfselect name="NameList" size="1" query="UserRole_q" value="EmpID" display="Name" selected="#temp#"><option value="-1"></option> </cfselect>

which pulls all employee names from the database and list as options.

so, to end my question , i need help placing this coldfusion query to replace the second dropdown ("SubOption1") in the javascript above. thank you for your time

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 04, 2015 0
Engaged ,
Aug 06, 2015

Copy link to clipboard

Copied

If you aren't going to be retrieving the options via Ajax the easiest solution is just to loop over the query within your JS:

var select = document.createElement("select");

//replace this second dropdown with the coldfusion query in below place

<cfoutput>

  <cfloop query="UserRole_q">

    var option = document.createElement("option");

    option.value = "#UserRole_q.empId#";

    option.text = "#UserRole_q.name#";

    select.appendChild(option);

  </cfloop>

</cfoutput>

document.getElementById("demob").appendChild(select);

Something like that should work.  You might have to tidy it up.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 06, 2015 0