• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1451
  • Last Modified:

Confirm Within ASP

This maybe a combination ASP and Javascript problem.
I am inserting/updating records.
May code snippet:
If objRS.EOF Then
Insert Record (works)
Else
**Now this is the problem portion
  msg="Division ID "+objRS("DivID")+ " already exists for "+objRS("DivName") & "."
  Response.Write "<" & "script language=javascript>"
  Response.Write "var msg = '"+msg+"';"
  Response.Write "var x=confirm(msg + '\nAre you sure you want to replace it?');"
         Response.Write "if(x==false)"
         Response.Write "{"
          Response.Write "window.history.go(-1);"  
                 Response.Write "}"
       Response.Write "<" & "/script>"       

 Update record.

When the user clicks on "Cancel" the app needs to go back to the previous page (which it does), but I need to the record not to be updated (which it is doing)!  

Thus, regardless of the user clicking "Ok" or "Cancel" the record is updated.  

Thank you.

LadyGail

0
LadyGail
Asked:
LadyGail
  • 7
  • 6
1 Solution
 
justinbilligCommented:
Since the javascript confirmation is client side you will need to resubmit the page
again after you do a confirm. The asp on this current page isnt contingent to weather or not you clicked OK. what you need to do is make a page that will hold all the request variables on an html form

<form name="formname" action="UpdatePage.asp">
<input type="hidden" name="field1" value="<%=Request.Form( "field1" )%>">

... etc

then on the onload do something like this

<body onload="if( confirm( "<%=Response.write( msg + "Do you want to replace it?")%>" ){ formname.submit( );}else{window.history.go(-1);}">
0
 
justinbilligCommented:
you would of course replace field1 with the names of your fields
0
 
LadyGailAuthor Commented:
It is not working.  

My code, on SendInfo.asp, was changed to reflect the following:

<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0"  OnLoad="if( confirm( "<%=Response.write( msg + "Do you want to replace it?")%>" ){ subadB.submit( );}else{window.history.go(-1);}">;InitMenu();optInit()"  Onclick="HideMenu(menuBar)" ID="Bdy">

<form name=SendInfo.asp action=UpdatePage.asp>
<input name="strViewDivID" type="text" id="strViewDivID" size="5" maxlength="2" >
<input type="hidden" name="strViewDivID2" value="<%=Request.Form("strViewDivID" )%>">

One the UpdatePage.asp, this error appears:
The following error message appears:
Microsoft OLE DB Provider for SQL Server error '80040e57'

String or binary data would be truncated.

/UpdatePage.asp, line 313


0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
justinbilligCommented:
that means your trying to insert a value into your table to long for that columns defintion


meaning if you specified a column as

varchar( 5 )

if you tried to insert '123456' it's telling you you can't do that cause your data would get truncated ( chopped off ) at '12345'
0
 
LadyGailAuthor Commented:
No, that's not the problem although it strongly appears to be so.  I am using the same test data now as I did before I posted my problem on EE.  The data inserted/updated without any difficulty before but only after I made the above mentioned changes did I see the error message I posted.
0
 
justinbilligCommented:
well then the data must be different

do a response.write on the SQL and check to see what data your actually inserting
0
 
LadyGailAuthor Commented:
Prior to my 02:43PM post, I checked the database to verify the size of the columns and they remaind unchanged.  The data is not different, for example, my test data is: 33 for DivID and the DivID column is 2 characters and Operations for DivName which is 22 characters for DivName and the DivName column is 22 characters.

To see if the confirm message box works I have been using  DivId of 33 and DivName of Operations to test for OK and 33 and Snoitarepo to test for False.

0
 
justinbilligCommented:
well it has to be somethign with your SQL cuase that is the SQL error

print out the SQL on the screen to see exactly what the insert statement is. Perhaps some javascript has caused the data to be changed on the page.
0
 
LadyGailAuthor Commented:
There is nothing wrong with my SQL.
I deleted your suggestion to place the conditional statement in the body onload.
Now that error message no longer appears.

I reverted everything back to my original code.
0
 
justinbilligCommented:
One the UpdatePage.asp, this error appears:
The following error message appears:
"Microsoft OLE DB Provider for SQL Server" error '80040e57'

String or binary data would be truncated.

/UpdatePage.asp, line 313




that signifies a SQL Error
0
 
LadyGailAuthor Commented:
When I removed:
<body onload="if( confirm( "<%=Response.write( msg + "Do you want to replace it?")%>" ){ formname.submit( );}else{window.history.go(-1);}">
that you suggested, the error ceased to occur.
0
 
justinbilligCommented:
that is becuase ( Like i said earlier ) the javascript may have changed somethign about the values you were submitting to the form.
0
 
LadyGailAuthor Commented:
My solution:
If objRS.EOF Then
 %>
 <script>
   window.location.href='UpdatePage.asp';
</script>
<%
Else
%>  
<script language=javascript>
var msg = '<%=msg%>';
var x=confirm('<%=msg%> \nAre you sure you want to replace it?');
if(x==true)
{
window.location.href='Conclusion.asp';
}
else if(x==false)
{
window.location.href='Original.asp';
}
</script>
 <%
End If

  objRS.Close
  objConn.Close
  Set objRS = Nothing
  Set objConn = Nothing
%>
0
 
moduloCommented:
PAQed with points refunded (125)

modulo
Community Support Moderator
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 7
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now