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

Using onChange for defined comments overwriting one another 1

Status
Not open for further replies.

squirleegirl

Programmer
Jun 24, 2003
59
US
Greetings!

I am very unfamiliar with javascript, so please bear with me.

I have an asp page that users enter training downtime in and a comment box for them to explain their downtime. The page is written in asp using standard text fields, text area html code.

I would like to standardize the comments by using the onChange function that when a user enters a value in one of the blocks, then the predefined comment for that blcok is automatically generated into the comments section (a text area). The code I am using is:

function CDT() {
document.SaveForm.DeviceComments.value = "Training lost to unscheduled maintenance due to <ENTER REASON> (ENTER HOURS)"
}

This is being activated with onChange='CDT()' for the block.

This works fine, but it doesn't add the comments to the text area, but rather overwrites what is there. There are several blocks that need to write to the same comments area. How can I get it to just add to the comments section instead of overwriting?

Also, this is a side-note, but thought I would ask anyways. How can I get the predefined comment to have the actual hours (value of the block) to the comment instead of having the user change the <ENTER HOURS> manually? Is there a way to incorporate the request.form into the javascript function?

I'm sure this is simple, but javascript is not a know-how of mine.

Thanks in advance for any advice!
 
Adding to the textarea, instead of replacing the values:
Code:
function CDT() {
    document.SaveForm.DeviceComments.value [red]+[/red]= "Training lost to unscheduled maintenance due to <ENTER REASON> (ENTER HOURS)"
    }

As for the next part - this is easy. But I'm not sure what you mean by "block". Is the HOUR value within a text field? If so, try this:

Code:
function CDT() {
    var val = document.SaveForm.FieldName.value;
    document.SaveForm.DeviceComments.value [red]+[/red]= "Training lost to unscheduled maintenance due to <ENTER REASON> (" + val + ")";
    }

*cLFlaVA
----------------------------
Lois: "Peter, you're drunk!"
Peter: "I'm not drunk, I'm just exhausted from stayin' up all night drinking!
 
Thanks for the help - the first suggestion worked great, but what is the code for a line break? It just makes it easier to read and less for the user to format (makes too many errors)

As far as the second code - yes the value of the block would be the number of hours - but the code didn't work. I'm using VisualDev to code and the only automatic options that it provides is for both my comment sections and the check button which indicates whether or not the comments print on the report. I don't get an error, but nothing happens. Can you direct me to where I can look for the problem?

I used your code (changing field name) and here is a copy of the code I'm using for the text area just in case:

<TR><TD><FONT face='Arial' size=1><STRONG>UNSCHEDULED MAINTENANCE</TD>
<%Counter = 1
Do While Not rs.EOF
sqlText= mysqlquery
Set rs2 = oConn.Execute(SqlText)
If rs2.EOF then%>
<TD><FONT face='ARial' size=1><INPUT type=text value='0.0' style='FONT-SIZE: xx-small' name='MaintenanceUnScheduledCharge<%=Counter%>' onChange='CDT()'></TD>
<%Else%>
<TD><FONT face='ARial' size=1><INPUT type=text value='<%=rs2("fldUnschedMaintcharge")%>' style='FONT-SIZE: xx-small' name='MaintenanceUnScheduledCharge<%=Counter%>' onChange='CDT()'></TD>
<%End If
Counter = Counter + 1
rs.movenext
Loop
rs.movefirst
Counter = 1%>

Also, can you direct me to a good learning tool for javascript?

Thanks again.
 
Line break = \n

Code:
function CDT() {
    document.SaveForm.DeviceComments.value += "\nTraining lost to unscheduled maintenance due to <ENTER REASON> (ENTER HOURS)"
    }

I suggest making the following change (for the hours problem):

Code:
function CDT(v) {
    document.SaveForm.DeviceComments.value += "\nTraining lost to unscheduled maintenance due to <ENTER REASON> (" + v + ")"
    }

And then:

Code:
onChange='CDT(this.value)'

*cLFlaVA
----------------------------
Lois: "Peter, you're drunk!"
Peter: "I'm not drunk, I'm just exhausted from stayin' up all night drinking!
 
:)

*cLFlaVA
----------------------------
Lois: "Peter, you're drunk!"
Peter: "I'm not drunk, I'm just exhausted from stayin' up all night drinking!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top