robn
Posts: 70
|
| Posted: 05/27/2005, 8:32 AM |
|
Hi I have an issue where I want to check on save the project number/name (alfa/numeric) that has been entered does not already exist in the database and if it does then I want a popup message to appear saying something similar to "A project already exists with this name are you sure you wish to save the record" with yes / no buttons.
The problem I have is I cant work out a way to get a yes / no popup using asp this is the following code I have been using which basically puts in a message at the top of the form saying that a project with this name already exists and the record will not save until you have changed the project name to be unique.
Function Validate()
Dim Validation
Dim Where
If EditMode Then
DataSource.BuildTableWhere
Where = " AND NOT (" & DataSource.Where & ")"
End If
If projno.Errors.Count = 0 Then
If CInt(CCDLookUp("COUNT(*)", " tblNPSProject LEFT JOIN tblNPSProjStatus ON tblNPSProject.Status = tblNPSProjStatus.SID", "projno=" & DBNPS.ToSQL(projno.Value, projno.DataType) & Where, DBNPS)) > 0 Then _
projno.Errors.addError("There is already a project with this name.")
End If
ValidatingControls.Validate
CCSEventResult = CCRaiseEvent(CCSEvents, "OnValidate", Me)
Validate = ValidatingControls.isValid() And (Errors.Count = 0)
End Function
I think you may be able to do this with a javascript but I can't write the code to get it working.
many thanks in advance
Rob N
|
 |
 |
smalloy
Posts: 107
|
| Posted: 05/31/2005, 1:32 PM |
|
I struggled with this as well and came up with this answer, but there are a few things you should know, you'll need an event to trigger the JavaScript. Believe me that programmatically changing text in a label does not constitute a onchange event. I do it when the page loads but you may need to fiddle around with finding an event to trigger the JavaScript.
Heres the script:
function correct_confirm(){
//Open the alert box and test for user response
var name=confirm("There is already a project with this name?" + '\n'
+ '\n' + "Press OK to Add Anyway Or Press Cancel to try again.")
if (name==true) {
do something
}else{
do something else
}
}
PS, remember that JavaScript is CASE Sensitive!!!! Else is some object you just created called Else, else is used for if, else.
I hope that this helps you, good luck.
_________________
Anything can be done, just give me time and money. |
 |
 |
|