×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Populating Text Box based on CFSelect Value

Populating Text Box based on CFSelect Value

Populating Text Box based on CFSelect Value

(OP)
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

RE: Populating Text Box based on CFSelect Value

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 --> Coldfusion

<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

CODE --> 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

RE: Populating Text Box based on CFSelect Value

(OP)
That worked! Thank you!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close