PDA

View Full Version : Alert and Confirm JavaScript


Abd
08-30-2002, 03:40 PM
Hi All,

I have a troubling script here, I actually want the script to check and compare the content of a RecordSet and a value entered in a textbox, if the value is NOT in the Recordset it should only display "Sequence Number Does Not Exit", else it should Delete the entered number from the Database.

But, currently for an existing Number it display the "Sequence Number Does Not Exit" before Deleting form the Database. Below is my code, I need assistant. Thanks, the code is below;

<%
category = TRIM( Request.Form( "cat" ) )
Pcode = TRIM( Request.Form( "Pcode" ) )

IF Pcode <> "" THEN
Set Con = Server.CreateObject( "ADODB.Connection" )
Con.Open "PROVIDER=SQLOLEDB;DATA SOURCE=ibank4;UID=sa;PWD=;DATABASE=nitel"
Set RS= Server.CreateObject( "ADODB.Recordset" )

RS.Open "Select sequence_number from nitel_bill_payment ", Con
SeqNum = RS.Fields("sequence_number")


If category = "Branch" then
mySQL = "DELETE from nitel_bill_payment WHERE sequence_number = '" &Pcode& "'"

End if
Con.Execute mySQL
Con.Close
Set RS = Nothing
Set Con = Nothing
END IF
%>


<html>
<head><title>Delete Sequence</title>
<body background="backg.gif" onload="Sequence()">
<h2 align="center"><font color="blue">Delete Sequence</font></h2>
<form name="val" method="post" action="deletentl.asp?cat">
<P><b>Enter Sequence Number:</b> <input name="pcode" size=4>
<input type="text" id="branch" name="cat" value="Branch">
<p><input type="submit" value="Delete" onClick="return Submit()">
</form>

<script language="JavaScript">
function Sequence()
{

//To Hide Branch Textbox
document.getElementById("branch").style.display = 'none'

}
</script>



<script language="JavaScript">
function Submit()
{

var Sequence;

Sequence = document.val.pcode.value;
if ( isNaN(Sequence) || Sequence.length<1){
alert ('Enter Sequence Number');
return false;
}


var SeqNum = SeqNum
if (Sequence != SeqNum){
alert ('Sequence Number Does Not Exit');

}
else
{
return true;
}

var stay=confirm("You have choose to DELETE the Sequence No. " + Sequence + " Click 'Ok' to delete, 'Cancel' to Stop!")
if (!stay)
return false;

}
</script>


<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<a href="defntl2.asp"><FONT FACE='COMIC Sans MS' COLOR=blue size=+1><h1 align="right">Menu</h1></FONT></a>


</body>
</html>