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

LadyGailAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.