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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populating Text Box based on CFSelect Value

Status
Not open for further replies.

cfuser10

Technical User
May 13, 2010
29
US
Hello,
I have a form that is used to input attendance. The attendance field is a cfselect from which the user chooses if the student was: present, absent, etc. There is also a comment field that is required to be completed for each student based upon their behavior in that class. If the student was absent, I would like to poplulate the comment box with the simple expression: Absent. That way the user does not have to enter a required comment for that person.

The relevant code in the form is as follows. The name of each control is variable based on the student id number. I'm not sure the correct way to go about trying to get the value of Absent to display in the textarea if Absent is selected for the attendance.

<cfoutput query="qryGetGroupMembers">
<tr><!--- One row for each scheduled student in the table --->
<td colspan="10">#last_name#, #first_name#</td>
<td><strong>Attendance Code:</strong>
<cfselect name="Att#idnum#" query="GetAttendance" value="Att_code" selected="T"
size="1" display="Att_desc" multiple="No" onChange="fnAttCode(this.value)" >
</cfselect><br><br>
</td>
<td align="left">
<strong>Comments</strong> (<font color="##FF0000"><strong>REQUIRED</strong></font>): <br />
<cftextarea name="txt#idnum#" required="yes" rows="4" cols="35" message="Please enter a comment for #last_name#, #first_name#"/>
</td>
</tr>
</cfoutput>

<script language="JavaScript">

function fnAttCode(val){
var code = val
if (code == 'A'){
document.getElementById('txt#cnum#').innerHTML ="Absent"
}
}

</script>

Hope this makes some sense. Thank you for any help that you can provide. I do not know Javascript and found the above example of code based on searching online.

Lisa
 
Couple quick changes. You have to send the id number of the textarea to the javascript so I added a dynamic id same as the textarea name and then also added it to the javascript call.

Code:
<cfoutput query="qryGetGroupMembers">
<tr><!--- One row for each scheduled student in the table --->
<td colspan="10">#last_name#, #first_name#</td>
<td><strong>Attendance Code:</strong> 
<cfselect name="Att#idnum#" query="GetAttendance" value="Att_code" selected="T" 
size="1" display="Att_desc" multiple="No" onChange="fnAttCode(this.value,'txt#idnum#')" >
</cfselect><br><br>
</td>
<td align="left">
<strong>Comments</strong> (<font color="##FF0000"><strong>REQUIRED</strong></font>): <br />	
<cftextarea id="txt#idnum#" name="txt#idnum#" required="yes" rows="4" cols="35" message="Please enter a comment for #last_name#, #first_name#"/>
</td>
</tr>
</cfoutput>

Javascript should read like this
JavaScript:
<script language="JavaScript">
function fnAttCode(val,user){
if (val == 'A'){
document.getElementById(user).innerHTML ="Absent"
}
}
</script>

If you can't stand behind your troops, stand in front of them.
Semper Fidelis

Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top