Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Message Box - Click OK Twice

New Here ,
Dec 19, 2010 Dec 19, 2010

ASP

Dreamweaver CS4

Hi All,

I have a Server-Side VBScript -> Client-Side JS Alert Message Box based on whether or not there is a duplicate entry in an access database.

If Not rsDuplicates.EOF Then

   msg = "This Player Is Already Registered"
    Response.Write("<" & "script>alert('" & msg & "');")
    Response.Write("<" & "/script>")

ElseIf (CStr(Request("MM_insert")) = "form1") Then etc.

The Message Box works OK and stops duplicate entries, however, you have to click OK twice before the box closes.

Any help, greatly appreciated

Regards

TOPICS
Server side applications
599
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 19, 2010 Dec 19, 2010

There is nothing in that code block that would cause that. You need to post the entire code from the page.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 20, 2010 Dec 20, 2010

Hi,

Many thanks for reply. Full code below.

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file=setlcid.inc -->
<%
SetLCID   'Set the Locale ID per the browser
%>

<%
Function PCase(strInput)
    Dim iPosition ' Our current position in the string (First character = 1)
    Dim iSpace ' The position of the next space after our iPosition
    Dim strOutput ' Our temporary string used to build the function's output

    iPosition = 1

    Do While InStr(iPosition, strInput, " ", 1) <> 0
            iSpace = InStr(iPosition, strInput, " ", 1)
            strOutput = strOutput & UCase(Mid(strInput, iPosition, 1))
            strOutput = strOutput & LCase(Mid(strInput, iPosition + 1, iSpace - iPosition))
            iPosition = iSpace + 1
    Loop

    strOutput = strOutput & UCase(Mid(strInput, iPosition, 1))
    strOutput = strOutput & LCase(Mid(strInput, iPosition + 1))

    PCase = strOutput
End Function
%>

<%
' *** Restrict Access To Page: Grant or deny access to this page
MM_authorizedUsers=""
MM_authFailedURL="UserLogin.asp"
MM_grantAccess=false
If Session("MM_Username") <> "" Then
  If (true Or CStr(Session("MM_UserAuthorization"))="") Or _
         (InStr(1,MM_authorizedUsers,Session("MM_UserAuthorization"))>=1) Then
    MM_grantAccess = true
  End If
End If
If Not MM_grantAccess Then
  MM_qsChar = "?"
  If (InStr(1,MM_authFailedURL,"?") >= 1) Then MM_qsChar = "&"
  MM_referrer = Request.ServerVariables("URL")
  if (Len(Request.QueryString()) > 0) Then MM_referrer = MM_referrer & "?" & Request.QueryString()
  MM_authFailedURL = MM_authFailedURL & MM_qsChar & "accessdenied=" & Server.URLEncode(MM_referrer)
  Response.Redirect(MM_authFailedURL)
End If
%>
<!--#include file="../Connections/Scricket49.asp" -->
<!--#include file="../Connections/Scricket40.asp" -->
<%
Dim MM_editAction
MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))
If (Request.QueryString <> "") Then
  MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString)
End If

' boolean to abort record edit
Dim MM_abortEdit
MM_abortEdit = false
%>
<%
' IIf implementation
Function MM_IIf(condition, ifTrue, ifFalse)
  If condition = "" Then
    MM_IIf = ifFalse
  Else
    MM_IIf = ifTrue
  End If
End Function
%>
<%
sUser=Request.Form("Club_User")
sInitial=Request.Form("Initial")
sLastName=Request.Form("Player_Name")

Dim rsDuplicates
Dim rsDuplicates_cmd
Dim rsDuplicates_numRows

Set rsDuplicates_cmd = Server.CreateObject ("ADODB.Command")
rsDuplicates_cmd.ActiveConnection = MM_Scricket40_STRING
rsDuplicates_cmd.CommandText = "SELECT * FROM tblPlayers WHERE Initial='" & sInitial & "' AND Player_Name='" & sLastName & "' AND UserName='" & sUser & "'"
rsDuplicates_cmd.Prepared = true
rsDuplicates_cmd.Parameters.Append rsDuplicates_cmd.CreateParameter("param1", 200, 1, 50, rsDuplicates__MMColParam) ' adVarChar


Set rsDuplicates = rsDuplicates_cmd.Execute
rsDuplicates_numRows = 0

If Not rsDuplicates.EOF Then

   msg = "This Player Is Already Registered"
    Response.Write("<" & "script>alert('" & msg & "');")
    Response.Write("<" & "/script>")

ElseIf (CStr(Request("MM_insert")) = "form1") Then
  If (Not MM_abortEdit) Then
    ' execute the insert
    Dim MM_editCmd

    Set MM_editCmd = Server.CreateObject ("ADODB.Command")
    MM_editCmd.ActiveConnection = MM_Scricket40_STRING
    MM_editCmd.CommandText = "INSERT INTO tblPlayers ([Initial], Player_Name, Under19, DOB, Club_Code, UserName) VALUES (?, ?, ?, ?, ?, ?)"
    MM_editCmd.Prepared = true
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 202, 1, 1, Request.Form("Initial")) ' adVarWChar
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param2", 202, 1, 50, Request.Form("Player_Name")) ' adVarWChar
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param3", 5, 1, -1, MM_IIF(Request.Form("chk"), 1, 0)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param4", 135, 1, -1, MM_IIF(Request.Form("dob"), Request.Form("dob"), null)) ' adDBTimeStamp
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param5", 202, 1, 50, Request.Form("Club_Code")) ' adVarWChar
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param6", 202, 1, 255, Request.Form("Club_User")) ' adVarWChar
    MM_editCmd.Execute
    MM_editCmd.ActiveConnection.Close
  End If
End If
%>
<%
Dim rsClub__MMColParam
rsClub__MMColParam = "1"
If (Session("MM_Username") <> "") Then
  rsClub__MMColParam = Session("MM_Username")
End If
%>
<%
Dim rsClub
Dim rsClub_cmd
Dim rsClub_numRows

Set rsClub_cmd = Server.CreateObject ("ADODB.Command")
rsClub_cmd.ActiveConnection = MM_Scricket49_STRING
rsClub_cmd.CommandText = "SELECT * FROM tblClubCodes WHERE ClubUser = ?"
rsClub_cmd.Prepared = true
rsClub_cmd.Parameters.Append rsClub_cmd.CreateParameter("param1", 200, 1, 15, rsClub__MMColParam) ' adVarChar

Set rsClub = rsClub_cmd.Execute
rsClub_numRows = 0
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Player Registration</title>
<link href="../style.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
body {
margin-top: 30px;
}
.Warning {
color: #F00;
}
-->
</style>
<script src="../SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<link href="../SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function strTrim(str) {
var elem = document.getElementById(str).value;
document.getElementById(str).value = elem.replace(/^\s+|\s+$/g, '');
}

function strProperCase(str) {
var elem = document.getElementById(str).value;
document.getElementById(str).value = elem.toLowerCase().replace(/^(.)|\s(.)/g,
function($1) { return $1.toUpperCase(); });
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
</script>

</head>

<body>
<table width="450" border="0" align="center" cellspacing="0">
  <tr>
    <td><div align="center" class="TableHeader"><%= UCase((rsClub.Fields.Item("ClubName").Value)) %> Player Registration</div></td>
  </tr>
  <tr>
    <td><div align="center">ENTER INITIAL, LAST NAME AND, IF THE PLAYER WAS UNDER 19 ON AUGUST 31st LAST YEAR, CHECK THE UNDER 19 CHECK BOX AND ENTER DATE OF BIRTH.</div></td>
  </tr>
 
  <tr>
    <td> 
      <form action="<%=MM_editAction%>" method="POST" name="form1" id="form1" >
        <table align="center">

          <tr valign="baseline">
            <td nowrap="nowrap" align="right">Initial:</td>
            <td><span id="sprytextfield1">
            <input name="Initial" type="text" class="textfield" id="Initial" onblur="strTrim('Initial');strProperCase('Initial')" value="" size="1" />
            <span class="textfieldRequiredMsg">Only 1 upper case initial permitted.</span><span class="textfieldInvalidFormatMsg">Only 1 upper case initial permitted.</span></span></td>
          </tr>
          <tr valign="baseline">
            <td nowrap="nowrap" align="right">Last Name:</td>
            <td><span id="sprytextfield2">
              <input name="Player_Name"  type="text" class="textfield" id="Player_Name" onblur="strTrim('Player_Name');strProperCase('Player_Name')" value="" size="32" />
            <span class="textfieldRequiredMsg">A name is required.</span></span></td>
          </tr>
          <tr valign="baseline">
            <td nowrap="nowrap" align="right">Under 19:</td>
            <td align="left" valign="middle"><input type="checkbox" id="chk" name="chk" value="True" size="2" /></td>
          </tr>
          <tr valign="baseline">
            <td colspan="2" align="right" nowrap="nowrap">If Under 19, please enter date of birth below. Format dd/mm/yy.</td>
          </tr>
          <tr valign="baseline">
            <td nowrap="nowrap" align="right"> </td>
            <td><span id="sprytextfield3">
            <input name="DOB" type="text" id="dob" class="textfield" value="" />
            <span class="textfieldInvalidFormatMsg">Invalid format.</span></span></td>
          </tr>
          <tr valign="baseline">
            <td nowrap="nowrap" align="right"> </td>
            <td><input type="submit" value="   Add   " />           </td>
          </tr>
        </table>
        <input type="hidden" name="MM_insert" value="form1" />
        <input type="hidden" name="Club_Code" value="<%=(rsClub.Fields.Item("ClubCode").Value)%>" size="32" />
        <input type="hidden" name="Club_User" value="<%=(rsClub.Fields.Item("ClubUser").Value)%>" size="32" />
       
      </form>
    </td>
  </tr>
  <tr>
    <td align="center">YOU CAN ONLY REGISTER ONE PLAYER WITH THE SAME INITIAL AND LAST NAME. IF YOU HAVE MORE THAN ONE PLAYER WITH THE SAME INITIAL AND LAST NAME THEN YOU MUST DISTINGUISH BETWEEN THE TWO BUY USING (Snr), (Jnr) ETC.</td>
  </tr>
  <tr>
    <td><div align="center" onclick="MM_openBrWindow('HelpFiles/PlayerRegistration.htm','Players','width=700,height=500')"><a href="javascript:void(0)">HELP</a></div></td>
  </tr>
  <tr>
    <td><div align="center"><a href="Welcome.asp">FORMS MENU</a></div></td>
  </tr>
  <tr>
    <td> </td>
  </tr>
</table>
<script type="text/javascript">
<!--
var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1", "custom", {pattern:"A"});
var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2");
var sprytextfield3 = new Spry.Widget.ValidationTextField("sprytextfield3", "date", {format:"dd/mm/yy", validateOn:["blur", "change"], isRequired:false});

//-->
</script>
</body>
</html>
<%
rsClub.Close()
Set rsClub = Nothing
%>
<%
rsDuplicates.Close()
Set rsDuplicates = Nothing
%>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 21, 2010 Dec 21, 2010
LATEST

Hi,

Problem solved.

The Code below should have been in the <html> tags. I have place in the <head> tags and it works fine.

<%
sUser=Request.Form("Club_User")
sInitial=Request.Form("Initial")
sLastName=Request.Form("Player_Name")

Dim rsDuplicates
Dim rsDuplicates_cmd
Dim rsDuplicates_numRows

Set rsDuplicates_cmd = Server.CreateObject ("ADODB.Command")
rsDuplicates_cmd.ActiveConnection = MM_Scricket40_STRING
rsDuplicates_cmd.CommandText = "SELECT Initial, Player_Name, UserName FROM tblPlayers WHERE Initial='" & sInitial & "' AND Player_Name='" & sLastName & "' AND UserName='" & sUser & "'"
rsDuplicates_cmd.Prepared = true
rsDuplicates_cmd.Parameters.Append rsDuplicates_cmd.CreateParameter("param1", 200, 1, 50, rsDuplicates__MMColParam) ' adVarChar


Set rsDuplicates = rsDuplicates_cmd.Execute
rsDuplicates_numRows = 0

If Not rsDuplicates.EOF Then

msg = "This Player Is Already Registered"
    Response.Write("<" & "script>alert('" & msg & "');")
    Response.Write("<" & "/script>")
  

ElseIf (CStr(Request("MM_insert")) = "form1") Then
  If (Not MM_abortEdit) Then
    ' execute the insert
    Dim MM_editCmd

    Set MM_editCmd = Server.CreateObject ("ADODB.Command")
    MM_editCmd.ActiveConnection = MM_Scricket40_STRING
    MM_editCmd.CommandText = "INSERT INTO tblPlayers ([Initial], Player_Name, Under19, DOB, Club_Code, UserName) VALUES (?, ?, ?, ?, ?, ?)"
    MM_editCmd.Prepared = true
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 202, 1, 1, Request.Form("Initial")) ' adVarWChar
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param2", 202, 1, 50, Request.Form("Player_Name")) ' adVarWChar
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param3", 5, 1, -1, MM_IIF(Request.Form("chk"), 1, 0)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param4", 135, 1, -1, MM_IIF(Request.Form("dob"), Request.Form("dob"), null)) ' adDBTimeStamp
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param5", 202, 1, 50, Request.Form("Club_Code")) ' adVarWChar
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param6", 202, 1, 255, Request.Form("Club_User")) ' adVarWChar
    MM_editCmd.Execute
    MM_editCmd.ActiveConnection.Close
  End If

End If
%>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines