Skip to main content
Participant
November 17, 2011
Question

ColdFusion - Javascript question

  • November 17, 2011
  • 2 replies
  • 1088 views

Hello all,

I am working on a page, where I have 3 drop downs, postionid,sid,restdays from table A with columns postionid,sid,res tdays. I am populating these dropdowns from the result of the cfquery i get. however, for the 3rd dropdown, Restdays, the data has to come from table B which columns are restdays, restdats description.

Now, when i select a position Id, from 1st dropdown, the 2nd and 3rd drop down should be the data related to that position id. That is Sid,restdaays should be coresponing to the position id. But since restdays dropdown is coming from a different table B, I need to be able to select the appropriate option from restday dropdown corresponding to the position id.

I have my code as below. I am using toscript to convert the coldfusion varibale to jscript variable. But I need to make the appropritate restday selected on select of the position id.

Please advise if this is the right way to do it.

<script type = "text/javascript">

function go1() {

var d = document.myform.sel1.selectedIndex;

document.myform.sel2.selectedIndex = d;

}

function go2() {

var d = document.myform.sel1.selectedIndex;

document.myform.sel3.selectedIndex = d;

}

function go3() {

var d = document.myform.sel1.selectedIndex;

document.myform.sel4.selectedIndex = d;

}

function go4() {

var d = document.myform.sel3.selectedIndex;

document.myform.sel1.selectedIndex = d;

}

</script>

<body>

<cfquery name="postndetail" datasource="mbtran">

select distinct position_id, schedule_group,accrual_profile,pay_rule_name,rest_days,effdt from kronos_if.position_detail

order by position_id, schedule_group,accrual_profile,pay_rule_name asc

</cfquery>

<cfquery name="postndetailrestday" datasource="mbtran">

select distinct position_id,rest_days from kronos_if.position_detail

<cfif isdefined("form.sel1")>

where position_id="#form.sel1#"

</cfif>

</cfquery>

<cfquery name="restdays" datasource="mbtran">

select rest_days,rest_day_descr from kronos_if.KRONOS_REST_DAY_DESCR

order by rest_day_id asc

</cfquery>

<cfset thisString="#postndetailrestday.rest_days#">

<cfoutput>#thisString# testest</cfoutput>

<script type="text/javascript" language="JavaScript">

    <cfoutput>

function dothis(){

        var #toScript(thisString, "jsVar")#;

alert(jsVar);

}

    </cfoutput>

</script>

<div align="center"><FONT size="+2">Update Position Details</FONT> </div><br/>

<form name="myform" action="updt_postn_details.cfm" method="post">

<cfoutput>

<table border="1" align="center">

      

<tr>

<td >Position ID</font></td>

<td align="left"><select name="sel1"

onchange = "go1();go2();go3();">

<cfloop query="postndetail">

<option value="#position_id#">#position_id#</option>

</cfloop>

</select></td>

</tr>

<input type="button" value="Go" onclick="dothis(this.form.submit);">

<tr>

<td>Schedule Group</td>

<td align="left"><select name="sel2">

<cfloop query="postndetail">

<option value="#schedule_group#">#schedule_group#</option>

</cfloop>

</select></td>

</tr>

<tr>

<td>Rest Days</td>

  <td align="left"><select name="sel5">

<cfloop query="restdays">

<option value="#rest_days#">#rest_days#  ||  #rest_day_descr#</option>

</cfloop>

</select></td>

</tr>

</table>

    This topic has been closed for replies.

    2 replies

    November 18, 2011

    Just out of curiousty did  you use pastebin to format your code?  If so, how did you copy it into the forum?

    Inspiring
    November 18, 2011

    What you are describing is a programming model called "Related Selects".  There is an excellent jQuery plug in that works great for this sort of thing:

    http://www.erichynds.com/examples/jquery-related-selects/

    Dipti85Author
    Participant
    November 19, 2011

    Thanks, but is there a way to do this in Coldfusion and javascript? Thanks in advance

    Inspiring
    November 19, 2011

    I kind of got lost in your code, but it is possible to do related selects with cf and js.  I do it like this:  http://www.pathcom.com/~bracuk/code/RelatedSelects.htm