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!

ASP/JavaScript not inserting into db correctly?

Status
Not open for further replies.

squirleegirl

Programmer
Jun 24, 2003
59
US
I'm not really sure if I should've posted this in another forum, but here goes anyways.

I have an application that users account for time in. There are several comment areas for them to explain downtime or whatever. In order to make the report look cleaner, we wanted standardized comments. So, several of the time entry blocks have an onChange statement in them to insert the generic statement for that area in appropriate comment box.

Problem: The database does not reflect the new comments. The record in the db shows the id, date, and whatever does not go through a javascript onChange function when the Save Record button is clicked. Now, if I clicked the Save button again, it would update the db with the comments.

I checked the insert query and it works fine. I can cut it out directly and paste it into sqlserver and it inserts the record with all of the correct comments. I have assumed the problem is somewhere with the javascript since this problem doesn't happen on the comments not run through the javascript functions.

Wierd thing, if I just do a Save Record where it enters the half record into the database and then pull a report, the comments are there.

There are 2 pages with 5 different comment sections that are run through javascript and they all act this way. Both of the comment sections that don't through javascript work fine.

I don't know if this is an actual problem with javascript or asp getting the information back from it.

Here is one of the javascript onChange functions:
function CDT(v) {
document.SaveForm.CDTComments.value += "\nTraining lost to unscheduled maintenance due to (" + v + " hours)"
}

Here is the block that activates the onChange:
<TR><TD><FONT face='Arial' size=1><STRONG>UNSCHEDULED MAINTENANCE</TD><TD><FONT face='Arial' size=1>(HRS)</TD>
<%Counter = 1
Do While Not rs.EOF
sqlText= SQLQuery
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(this.value)'></TD>
<%Else%>
<TD><FONT face='ARial' size=1><INPUT type=text value='<%=rs2("fldUnschedMaintcharge")%>' style='FONT-SIZE: xx-small' name='MaintenanceUnScheduledCharge<%=Counter%>' onChange='CDT(this.value)'></TD>
<%End If
Counter = Counter + 1
rs.movenext
Loop
rs.movefirst
Counter = 1%>

Here is the code that is run when the user clicks Save:
varCDTComments = Request.Form("CDTComments")
varCDTComments = unQuote(varCDTComments)
If Counter = 0 then
sqlText="INSERT QUERY"
Set rs3 = oConn.Execute(sqlText)
Else
sqlText = "UPDATE QUERY"
Set rs3 = oConn.Execute(sqlText)
End If

Like I said, I have double checked the insert query, the request.form, and the unQuote function and they all are functioning correctly. I don't know javascript well at all and this is driving me nuts!

Thanks for any help!
 
I don't quite understand the issue with the Javascript. ASP only "fires" if something is submitted to the server. Does the Javascript perform a submit? Remember that Javascript can only do things on the client side (though it can submit a request/form) and ASP can only do things on the server side.

Here's the logic of your application as I understand it, but I suspect I'm wrong, sp please straighten me out.

1. User enters data.

2. If user enters data in the comments field, some Javascript changes what's in the comments field.

3. User... somehow (this you haven't mentioned) indicates that he's done. Is this hitting the Save button or is the save feature something else, something for completing records in progress?

Where are you getting records saved that don't have comments? Sorry, dumb question probably, but I'm just not quite following the application logic.
 
Almost correct logic:

1) User enters data in text boxes. For example, one test box is called 'Unscheduled Maintenance'

2) When User leaves the box (either tab or mouse click), then the onChange(this.value) event is fired that signals the javascript to insert into the appropriate comments area a generic comments - in this case, 'Training lost to unscheduled maintenance due to XXXXX' in which case the user will manually change the XXXXX to identify the cause of the downtime.

3) The user clicks the 'Save Record' button to indicate they are done entering data. This then causes the application to gather the information from the page using request.form, etc. and do the inserts or updates into the database.

For example, one page has 2 different text fields that when the user enters a number into them, the onChange event is fired. There are 3 different comments sections - one for each of the 2 specific areas mentioned above that hold the generic comment generated by the onchange javascript function and one that is for miscellaneous comments that the user enters in manually. Once the user clicks save, the application is supposed to enter the all of the comments and the print/no print designator into a table ( the times are in a different table). However, the record only shows the id, date, location, device, the manual comments (if any), and all of the print/no print designators - none of the comments that are generated through the onChange event are there. Once I click the Save Record button again, the application does an Update instead of an insert. Now, all of the comments are in the database.

Frustrating!

 
Hmm, that is quite strange. Data in a form field should be data in a form field, whether entered by a user or by Javascript.

Is the Save Record button just a standard HTML submit, or does it have Javascript attached?
 
Just a standard HTML submit button.

Its weird that the comments show up on my report even though they are not in the database. Where are they!!!!
 
The report is opened into a MS Word document using standard html and ASP coding.
 
Sorry, what I mean is... is the report generated from the database as a standalone page, or is it, say, created on the page following the insert, or... something else?
 
Sorry, I'm blond =-)

The report is generated solely from the datbase with the exception of the location, month, and year combo boxes that indicate which report to pull.
 
Then somehow the comments must be going into the database. What makes you think they're not? That is, what are you using to view the contents of the database that leads you to that conclusion?
 
I am opening the table and viewing all the records. Obviously something is working right since the comments are on the report and if I close the application and go back into it, the comments are still there. But, I don't want to rely on the fact that it is working absolutely correct since I can't look in the database and see the records because as soon as I release this package, I can see it not working.
 
Hmm. Completely puzzling, sorry. I can't imagine how you'd have a form that submits data into a database, the data can't be seen in the database so it appears that it's not storing the data, yet a page that draws data from the database can, in fact, supply the information. Is there any chance you're not looking in the right database?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top