OutFront Forums
     Home    Register     Search      Help      Login    

Follow Us
On Facebook
On Twitter
RSS
Via Email

Recent Posts
Todays Posts
Most Active posts
Posts since last visit
My Recent Posts
Mark posts read

Sponsors
Shopping Cart Software
Ecommerce software integrated into Frontpage, Dreamweaver and Golive templates. No monthly fees and available in ASP and PHP versions.
Website Templates
We also have a wide selection of Dreamweaver, Expression Web and Frontpage templates as well as webmaster tools and CSS layouts.
Frontpage website templates
Creative Website Templates for FrontPage, Dreamweaver, Flash, SwishMax

 

Uniqueness check

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
Printable Version 

All Forums >> Web Development >> ASP, PHP, and Database >> Uniqueness check
Page: [1]
 
harris

 

Posts: 27
Joined: 2/7/2002
From: Minnesota USA
Status: offline

 
Uniqueness check - 3/1/2002 17:06:36   
Hi,
I have a form in which I'm calling a java script VALIDATE. Within that script, I'd like to check that the name entered is not blank (that IS working) and that the name is unique. That's the part that is not working. Here's what I have:

<script language="JavaScript">
<!--
function validate()
{
if (document.editform.projname.value=="")
{
alert ("You must enter a Project Name.")
document.editform.projname.focus()
return false
}

<%
Set objDC = Server.CreateObject("ADODB.Connection")
objDC.Open Application("wms30_connectionstring")
Set objRS = objDC.Execute("SELECT * FROM sim_group WHERE projname = '" & _
Request.Form("projname") & "'")

' check end of the recordset.
If objRS.EOF Then
'ok to continue
OktoAdd = "Y"
Else
OktoAdd = "N"
End If
' Close Data Access Objects and free DB variables
objRS.Close
Set objRS = Nothing
objDC.Close
Set objDC = Nothing
%>
if OktoAdd = "N"
{
alert ("You must enter a UNIQUE Project Name.")
document.editform.projname.focus()
return false
}

}
//-->
</script>


The problems seems to be related to using a variable (OktoAdd) in the ASP part but also using it in the java script part.

Thanks!
Harris


Mojo

 

Posts: 2472
From: Chicago
Status: offline

 
RE: Uniqueness check - 3/2/2002 0:05:45   
The problems seems to be related to using a variable (OktoAdd) in the ASP part but also using it in the java script part.

Correct. ASP and any variables used in ASP are all on the server - JavaScript is on the client. You need to pass the ASP variable to Javascript. Something like:

<script language="JavaScript">
var jsVariable = "<%=ASPVariable%>"
</script>

Joe



(in reply to harris)
harris

 

Posts: 27
Joined: 2/7/2002
From: Minnesota USA
Status: offline

 
RE: Uniqueness check - 3/4/2002 12:54:11   
Hi Joe,
Thanks so much for your response! That code will be very useful.

However, I am getting an error with this page. Can you tell what is wrong? Is it wrong to have asp code within a java script function?

Thanks!
Harris


(in reply to harris)
Mojo

 

Posts: 2472
From: Chicago
Status: offline

 
RE: Uniqueness check - 3/4/2002 13:08:47   
That all depends on what your doing...

What is the error?

Joe


(in reply to harris)
William Lee

 

Posts: 1273
Joined: 1/25/2002
From: Singapore
Status: offline

 
RE: Uniqueness check - 3/4/2002 13:38:55   
Declare the var OktoAdd first



William Lee

(in reply to harris)
harris

 

Posts: 27
Joined: 2/7/2002
From: Minnesota USA
Status: offline

 
RE: Uniqueness check - 3/4/2002 14:00:52   
Thanks Joe & William!

I have fixed the error. It was syntax on my java script if statement. I had omitted ().

Now, however, it is not reading this correctly. It is always setting aspOKtoAdd to N regardless of what I enter into the form. I'm guessing something is wrong with the select statement.

Here's what I have (the check on blank input IS working):

<script language="JavaScript">
<!--
function validate()
{
if (document.editform.projname.value=="")
{
alert ("You must enter a Project Name.")
document.editform.projname.focus()
return false
}

<%
Set objDC = Server.CreateObject("ADODB.Connection")
objDC.Open Application("wms30_connectionstring")
Set objRS = objDC.Execute("SELECT * FROM sim_group WHERE projname = '" & _
Request.Form("projname") & "'")

' check end of the recordset.
If objRS.EOF Then
'ok to continue
aspOktoAdd = "Y"
Else
aspOktoAdd = "N"
End If
' Close Data Access Objects and free DB variables
objRS.Close
Set objRS = Nothing
objDC.Close
Set objDC = Nothing
%>

var jsOktoAdd = "<%=aspOktoAdd%>"

if (jsOktoAdd = "N")
{
alert ("You must enter a UNIQUE Project Name.")
document.editform.projname.focus()
return false
}
}
//-->
</script>

Thanks!
Harris


(in reply to harris)
William Lee

 

Posts: 1273
Joined: 1/25/2002
From: Singapore
Status: offline

 
RE: Uniqueness check - 3/4/2002 14:05:46   
Should be

If objRS.EOF Then
'NOT ok to continue
aspOktoAdd = "N"
Else
....

If you reach the EOF,that means there is NO match, meaning you go back and give me a valid projname


William Lee

Edited by - William Lee on 03/04/2002 14:10:26

(in reply to harris)
harris

 

Posts: 27
Joined: 2/7/2002
From: Minnesota USA
Status: offline

 
RE: Uniqueness check - 3/4/2002 14:23:09   
Actually, in this case, I only want to add when the name is unique. The user is adding records to a project table and they need to enter a unique project name. What you are saying applies when the users wants to use a project name from names already added. Sorry for not making this clear!

I am still at the same problem, that is aspOktoAdd is N regardless of input.

Thanks!
Harris


(in reply to harris)
William Lee

 

Posts: 1273
Joined: 1/25/2002
From: Singapore
Status: offline

 
RE: Uniqueness check - 3/4/2002 23:30:49   
Do you have an empty table? I'm guessing BOF comes before EOF and causes the If statement to assign "N" always.



William Lee

(in reply to harris)
harris

 

Posts: 27
Joined: 2/7/2002
From: Minnesota USA
Status: offline

 
RE: Uniqueness check - 3/5/2002 15:28:46   
Thanks for your response William!

No, my table is not empty.

It seems that the ASP code within the Java script function is executing when the screen is loaded and does not re-execute when the function is called. Thus, the value of aspOktoAdd never changes.

If this is the case, how do I re-write this so the ASP code executes with the function?

Thanks!
Harris


(in reply to harris)
William Lee

 

Posts: 1273
Joined: 1/25/2002
From: Singapore
Status: offline

 
RE: Uniqueness check - 3/5/2002 15:53:44   
Try this?

<script language="JavaScript">
<!--
function validate()
{
if (document.editform.projname.value=="")
{
alert ("You must enter a Project Name.")
document.editform.projname.focus()
return false
}

<%
Set objDC = Server.CreateObject("ADODB.Connection")
objDC.Open Application("wms30_connectionstring")
Set objRS = objDC.Execute("SELECT * FROM sim_group WHERE projname = '" & _
Request.Form("projname") & "'")

' check end of the recordset.
If NOT objRS.EOF Then

Response.write("{" & vbNewline)
Response.write("alert ("You must enter a UNIQUE Project Name.")" & vbNewline)
Response.write("document.editform.projname.focus()" & vbNewline)
Response.write("return false" & vbNewline)
Response.write("}" & vbNewline)


End If
' Close Data Access Objects and free DB variables
objRS.Close
Set objRS = Nothing
objDC.Close
Set objDC = Nothing
%>


//-->
</script>


William Lee

(in reply to harris)
harris

 

Posts: 27
Joined: 2/7/2002
From: Minnesota USA
Status: offline

 
RE: Uniqueness check - 3/5/2002 16:08:25   
Hi William,
This did not work. A similiar problem is happening. Now I can enter any value and it will be accepted - even when the value was already entered. Before, any value entered would not be accepted - even when the value was not entered.

Is there something wrong with the select statement?

Thanks!
Harris


(in reply to harris)
William Lee

 

Posts: 1273
Joined: 1/25/2002
From: Singapore
Status: offline

 
RE: Uniqueness check - 3/5/2002 16:14:35   
Response.Write objRS("projname") and see what value it gives when you type in a name.

William Lee

(in reply to harris)
harris

 

Posts: 27
Joined: 2/7/2002
From: Minnesota USA
Status: offline

 
RE: Uniqueness check - 3/5/2002 16:51:22   
I do not get anything when I Response.Write objRS("projname"). In fact, the screen does not even fill in.

I put an alert right before the ASP code, and that gives me what I entered. Here's that code:
alert (document.editform.projname.value)

Do you think the projname value from the form is getting into the ASP code?

Thanks!
Harris



(in reply to harris)
William Lee

 

Posts: 1273
Joined: 1/25/2002
From: Singapore
Status: offline

 
RE: Uniqueness check - 3/5/2002 17:04:21   
quote:


Do you think the projname value from the form is getting into the ASP code?




When the user press the form submit button, the onsubmit start the validation..
If not empty then the form is submitted...to itself?

<%=Request.Form("projname")%> at the top and see if value passed to form. Don't see why not

William Lee

(in reply to harris)
harris

 

Posts: 27
Joined: 2/7/2002
From: Minnesota USA
Status: offline

 
RE: Uniqueness check - 3/5/2002 18:37:09   
I can not get <%=Request.Form("projname")%> to work. You mentioned to put it at the top. Top of what? I put it at the top of the of validate function. Is that right? Would this only work if the validate function was on a separate page?

This is how I'm calling the validate function which exists on the same page:
<form method="POST" action="simulations_groups_add_confirmation.asp" name="editform" onsubmit="return validate()">
The confirmation page updates the database.

Thanks so much for your help!
Harris


(in reply to harris)
William Lee

 

Posts: 1273
Joined: 1/25/2002
From: Singapore
Status: offline

 
RE: Uniqueness check - 3/5/2002 19:02:17   
Hi harris

May I suggest you use the Validate() to check for non-empty entries only. If user fills in something, then the form submits to the .asp page.
On the .asp page, use the existing code to check for unique projname. If projname is unique then updates database. If not unique, then
Response.Redirect "formpage.asp?Msg=NotUnique"

On the formpage.asp, have an ASP snippet like
<%
If Request("Msg")="NotUnique" Then
Response.Write "Please enter a Unique name"
End if %>



Edited by - William Lee on 03/05/2002 19:03:44

(in reply to harris)
harris

 

Posts: 27
Joined: 2/7/2002
From: Minnesota USA
Status: offline

 
RE: Uniqueness check - 3/5/2002 21:29:27   
So there is no way to call a function to replace that ASP code? If there is, I would perfer that so the messages to the user look the same.

Thanks!
Harris


(in reply to harris)
William Lee

 

Posts: 1273
Joined: 1/25/2002
From: Singapore
Status: offline

 
RE: Uniqueness check - 3/6/2002 2:57:20   
quote:

So there is no way to call a function to replace that ASP code? If there is, I would perfer that so the messages to the user look the same.

Thanks!
Harris





<% If Msg="NotUnique" Then

Response.write("<script language=""JavaScript"">" & vbNewline)
Response.write("{" & vbNewline)
Response.write("alert ("You must enter a UNIQUE Project Name.")" & vbNewline)
Response.write("document.editform.projname.focus()" & vbNewline)
Response.write("return false" & vbNewline)
Response.write("}" & vbNewline)
Response.write("</script>" & vbNewline)

End If
%>


William Lee

(in reply to harris)
William Lee

 

Posts: 1273
Joined: 1/25/2002
From: Singapore
Status: offline

 
RE: Uniqueness check - 3/6/2002 6:38:07   
quote:


<% If Msg="NotUnique" Then

Response.write("<script language=""JavaScript"">" & vbNewline)
Response.write("{" & vbNewline)
Response.write("alert ("You must enter a UNIQUE Project Name.")" & vbNewline)
Response.write("document.editform.projname.focus()" & vbNewline)
Response.write("return false" & vbNewline)
Response.write("}" & vbNewline)
Response.write("</script>" & vbNewline)

End If
%>




Change the problematic alert prompt line to single quote:

Response.write("alert ('You must enter a UNIQUE Project Name.')" & vbNewline)


William Lee

(in reply to harris)
harris

 

Posts: 27
Joined: 2/7/2002
From: Minnesota USA
Status: offline

 
RE: Uniqueness check - 3/6/2002 8:54:35   
This is working to capture the uniqueness, but two things are not working quite right.

1. The message within the response.write when Msg="NotUnique" is not showing up. Where should that code be placed?

2. The value of all the fields return to blank under this condition. I want the values to remain. Do I have to pass parameters?

Thanks!
Harris



Edited by - harris on 03/06/2002 08:56:52

(in reply to harris)
William Lee

 

Posts: 1273
Joined: 1/25/2002
From: Singapore
Status: offline

 
RE: Uniqueness check - 3/6/2002 9:05:16   
1. The message within the response.write when Msg="NotUnique" is not showing up. Where should that code be placed?

Place it on the formpage.asp, the page that the user is redirected back to when the name he submitted is not unique. The same page that the Validate() is on. What page did you put on?

Can you show me the URL to your webpage?


William Lee

(in reply to harris)
harris

 

Posts: 27
Joined: 2/7/2002
From: Minnesota USA
Status: offline

 
RE: Uniqueness check - 3/7/2002 21:58:22   
I have placed it on the form page. Is there a particular place on that page that it should be? Should the msg clause contain a request statement?

This site is not a public site so unfortunately I can not share the url.

Also, any ideas on the blank values?

Thanks!
Harris


(in reply to harris)
William Lee

 

Posts: 1273
Joined: 1/25/2002
From: Singapore
Status: offline

 
RE: Uniqueness check - 3/8/2002 4:36:56   
Hi harris
I am not sure if I am helping you at all or are you doing it the way I think will give the desired results. I have the idea that I am not understanding you.

What is not working now? Can you please elaborate.



William Lee

(in reply to harris)
harris

 

Posts: 27
Joined: 2/7/2002
From: Minnesota USA
Status: offline

 
RE: Uniqueness check - 3/8/2002 8:52:06   
Sorry for not being clear!

This is what is not working:
1. The message within the response.write when Msg="NotUnique" is not showing up. This is the code I have placed on the form page:

<% If (request("Msg")="NotUnique") Then
Response.write("<script language=""JavaScript"">" & vbNewline)
Response.write("{" & vbNewline)
Response.write("alert ('You must enter a UNIQUE Project Name.')" & vbNewline)
Response.write("document.editform.projname.focus()" & vbNewline)
Response.write("return false" & vbNewline)
Response.write("}" & vbNewline)
Response.write("</script>" & vbNewline)
End If
%>

When this page comes up with the Msg="NotUnique", I get a message on the botton left of the screen "Done, but with errors on the page". It does not elaborate on the error. Maybe it does't like the ""JavaScript"" ????

2. The value of all the fields return to blank under this condition. I want the values to remain. Do I have to pass parameters?

If we can get this to work, that would be ok. My first choice would be to try to test for uniqueness before submitting the page. This way, all the error checks will be done in a similar way - that is checking the value field by field. This is what we were initially trying but to no avail. I have read other uniqueness checks and they all do it as you are suggesting - that is testing for uniqueness after submitting.

Thanks!
Harris



(in reply to harris)
William Lee

 

Posts: 1273
Joined: 1/25/2002
From: Singapore
Status: offline

 
RE: Uniqueness check - 3/8/2002 10:18:35   
You cannot test for uniqueness unless you have checked with the server and that means you have to submit the form first.

If it is not too long, can you post the source code of your form page.



William Lee

(in reply to harris)
harris

 

Posts: 27
Joined: 2/7/2002
From: Minnesota USA
Status: offline

 
RE: Uniqueness check - 3/8/2002 10:53:36   
ok, I understand about submitting. Thank you.

Here is the code. I took out some scripts that I didn't think was relevant to this topic in order to decrease the size.

<html>

<head>

<LINK REL=STYLESHEET TYPE="text/css" HREF="site.css">

<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Simulations - Groups Entering - Add</title>

<!--#INCLUDE File="hovercolors.inc"-->

<% If (request("Msg")="NotUnique") Then
Response.write("<script language=""JavaScript"">" & vbNewline)
Response.write("{" & vbNewline)
Response.write("alert ('You must enter a UNIQUE Project Name.')" & vbNewline)
Response.write("document.editform.projname.focus()" & vbNewline)
Response.write("return false" & vbNewline)
Response.write("}" & vbNewline)
Response.write("</script>" & vbNewline)
End If
%>

<script language="JavaScript">
<!--
function validate()
{
if (document.editform.projname.value=="")
{
alert ("You must enter a Group Name.")
document.editform.projname.focus()
return false
}
}
//-->
</script>

<script language="JavaScript" fptype="dynamicanimation">
<!--
function dynAnimation() {}
function clickSwapImg() {}
//-->
</script>
<script language="JavaScript1.2" fptype="dynamicanimation" src="animate.js">
</script>
</head>

<BODY marginwidth="0" marginheight="0" style="margin: 0" onLoad="writeMenus()" onResize="if (isNS4) nsResizeHandler()">
<SCRIPT LANGUAGE="Javascript"
SRC="hovermenu.js">
</SCRIPT>

<table border="0" width="750" cellspacing="0" cellpadding="0">
<tr>
<td width="100%"><table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td width="100%"><table width="750" cellspacing="0" cellpadding="0" bgcolor="#00009D">
<tr>
<td colspan="2" bgcolor="#FFFFFF"><img border="0" src="images/line_shadow.bmp"></td>
</tr>
<tr>
<td><img border="0" src="images/wms30line.bmp"></td>
<td valign="middle"><p align="right"><font color="#FFFFFF" size="2"><b><%response.write session("sViewname")%> </b></font></p></td>
</tr>
<tr>
<td colspan="2" bgcolor="#FFFFFF"><img border="0" src="images/line_shadow.bmp"></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="2" bgcolor="#FFFFFF"><img border="0" src="images/line_shadow.bmp"></td>
</tr>
<tr>
<td width="100%" colspan="2" bgcolor="#000080">
<p align="left"><font size="1" color="#FFFFFF"> 
Last MMIS Update <b><%response.write session("sCurr_updt")%></b></font></p>
</td>
</tr>
<tr>
<td colspan="2" bgcolor="#FFFFFF"><img border="0" src="images/line_shadow.bmp"></td>
</tr>
</table></td>
</tr>
<tr>
<td width="100%"><table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td width="98%" valign="middle"><p align="center"><img border="0" src="images/title_sg_add.bmp" width="370" height="33"></td>
<td width="2%" valign="middle"> 
<p> </td>
</tr>
<tr>
<td width="100%" colspan="2"></td>
</tr>
<tr>
<td width="100%" colspan="2"><form method="POST" action="simulations_groups_add_confirmation.asp" name="editform" onsubmit="return validate()">
<table border="0" width="100%" cellspacing="1" cellpadding="0">

<tr>
<td width="11%" rowspan="11"> </td>
<td width="66%" colspan="2" bgcolor="#76765C">
<p align="center"><b><font size="1" color="#FFFFFF">Group Information</font></b></td>
<td width="11%" rowspan="11"></td>
<td width="56%" bgcolor="#76765C">
<p align="center"><b><font size="1" color="#FFFFFF">Group Notes</font></b></td>
</tr>
<tr>
<td width="33%" bgcolor="#E4E3DC"><font size="1">Group
Name</font></td>
<td width="33%" bgcolor="#E4E3DC">
<font size="1"><input type="text" name="projname" size="10" tabindex="1"></font>
</td>
<td width="56%" rowspan="10" valign="top">

<p><textarea rows="11" name="notes" cols="46" tabindex="9"></textarea></td>
</tr>
<tr>
<td width="33%" bgcolor="#E4E3DC"><font size="1">Co
FR</font></td>
<td width="33%" bgcolor="#E4E3DC"><font size="2"><b><%response.write session("sViewcode")%></b></font></td>
</tr>
<tr>
<td width="33%" bgcolor="#E4E3DC"><font size="1">Date
Submitted</font></td>
<td width="33%" bgcolor="#E4E3DC"><font size="2"><b><%response.write date()%></b></font></td>
</tr>
<tr>
<td width="33%" bgcolor="#E4E3DC"><font size="1">Closure</font></td>
<td width="33%" bgcolor="#E4E3DC">
<font size="1"><input type="text" name="closure" size="1" value=" " tabindex="2"></font></td>
</tr>
<tr>
<td width="33%" bgcolor="#E4E3DC"><font size="1">Simulated
In Date</font></td>
<td width="33%" bgcolor="#E4E3DC"><font size="1"><input type="text" name="indate_s" size="10" tabindex="4"></font></td>
</tr>
<tr>
<td width="33%" bgcolor="#E4E3DC"><font size="1">Simulated
Authorized Average</font></td>
<td width="33%" bgcolor="#E4E3DC"><font size="1"><input type="text" name="avg_auths" size="7" tabindex="5"></font></td>
</tr>
<tr>
<td width="33%" bgcolor="#E4E3DC"><font size="1">Simulated
Allowable Average</font></td>
<td width="33%" bgcolor="#E4E3DC"><font size="1"><input type="text" name="avg_allos" size="7" tabindex="6"></font></td>
</tr>
<tr>
<td width="33%" bgcolor="#E4E3DC"><font size="1">#
in Group</font></td>
<td width="33%" bgcolor="#E4E3DC"><font size="1"><input type="text" name="recp_s" size="4" tabindex="7"></font></td>
</tr>
</table>


<p align="center"><input dynamicanimation="fpAnimformatRolloverFP1" fprolloverstyle="color: #000080; background-color: <%=bghover%>" onmouseover="rollIn(this)" onmouseout="rollOut(this)" language="Javascript1.2" type="submit" value="Submit" name="B1" style="background-color: #EDF1F3; color: #000080"><input dynamicanimation="fpAnimformatRolloverFP1" fprolloverstyle="color: #000080; background-color: <%=bghover%>" onmouseover="rollIn(this)" onmouseout="rollOut(this)" language="Javascript1.2" type="reset" value="Reset" name="B2" style="background-color: #EDF1F3; color: #000080"><br>
<a href="javascript:history.go(-1)" dynamicanimation="fpAnimformatRolloverFP1" fprolloverstyle="color: #000080; background-color: <%=bghover%>" onmouseover="rollIn(this)" onmouseout="rollOut(this)" language="Javascript1.2"><font size="1">Back
to Previous Page WITHOUT Adding</font></a></p>
</form>
</td>
</tr>
<tr>
<td width="100%" colspan="2"></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table> </body>

</html>

Thanks!
Harris


(in reply to harris)
William Lee

 

Posts: 1273
Joined: 1/25/2002
From: Singapore
Status: offline

 
RE: Uniqueness check - 3/8/2002 11:07:07   
Change this portion:

<% If (request("Msg")="NotUnique") Then
Response.write("<script language=""JavaScript"">" & vbNewline)

Response.write("alert ('You must enter a UNIQUE Project Name.')" & vbNewline)
Response.write("document.editform.projname.focus()" & vbNewline)


Response.write("</script>" & vbNewline)
End If
%>

To retain the field values, put the value for each formfield like this <%=Request("notes")%> for notes.


Edited by - William Lee on 03/08/2002 11:09:36

(in reply to harris)
harris

 

Posts: 27
Joined: 2/7/2002
From: Minnesota USA
Status: offline

 
RE: Uniqueness check - 3/8/2002 12:32:53   
William,
You may not believe this - but I got it!

Here's a recap of everything so readers can refer to this rather than weed through all my mistakes!

1. On the form page, put the value for each formfield like this (projname represents any field):
<input type="text" name="projname" size="10" value="<%=request("projname")%>" onblur="projnamefix()" tabindex="1">

This will retain the values of the fields when the uniqueness routine is used on the subsequent page. When the user first enters the page, no parameters are passed, so the values will be blank.

2. On the form page, put this code AFTER the form tags. The page will error out if placed before the form tags. I put this after the </body> tag such that the page will be filled in behind the message.

<% If (request("Msg")="NotUnique") Then
Response.write("<script language=""JavaScript"">" & vbNewline)
Response.write("alert ('You must enter a UNIQUE Project Name.')" & vbNewline)
Response.write("document.editform.projname.focus()" & vbNewline)
Response.write("</script>" & vbNewline)
End If
%>

3. On the form page, here is the form tag:
<form method="POST" action="simulations_groups_add_confirmation.asp" name="editform" onsubmit="return validate()">

4. On the form page, I am using on blur to change to upper case and to remove leading blanks. If the value is blank, the user can still get off this field so they can abort the action. The blank check is in the validate function (step 5). Here is the on blur code:

<script language="JavaScript">
<!--
function projnamefix()
{
document.editform.projname.value=document.editform.projname.value.toUpperCase()
// remove leading spaces
document.editform.projname.value=document.editform.projname.value.substr(document.editform.projname.value.lastIndexOf(" ")+1)
}
//-->
</script>


5. On the form page in the validate function, I am checking for not blank entries. The uniqueness check is found on the action page (step 6). Here is the code:

<script language="JavaScript">
<!--
function validate()
{
if (document.editform.projname.value=="")
{
alert ("You must enter a Group Name.")
document.editform.projname.focus()
return false
}
}
//-->
</script>

6. On the action page, I am checking for uniqueness. Here is the code I have at the beginning of the action page:
<%
Set objDC = Server.CreateObject("ADODB.Connection")
objDC.Open Application("wms30_connectionstring")
Set objRS = objDC.Execute("SELECT * FROM sim_group WHERE projname = '" & Request("projname") & "'")
' check end of the recordset.
If NOT objRS.EOF Then
' Close Data Access Objects and free DB variables
objRS.Close
Set objRS = Nothing
objDC.Close
Set objDC = Nothing
Response.Redirect "simulations_groups_add.asp?Msg=NotUnique&projname="&request("projname")&"&closure="&request("closure")&"&indate_s="&request("indate_s")&"&avg_auths="&request("avg_auths")&"&avg_allos="&request("avg_allos")&"&recp_s="&request("recp_s")&"¬es="&request("notes")
End If
' Close Data Access Objects and free DB variables
objRS.Close
Set objRS = Nothing
objDC.Close
Set objDC = Nothing
%>

If the value has been found (or not unique), I am redirecting back to the form page passing all the values such that the form page will not have blank values.

I couldn't have done this without your help, William. Many, many thanks!! I hope this helps others!
Harris



(in reply to harris)
Page:   [1]

All Forums >> Web Development >> ASP, PHP, and Database >> Uniqueness check
Page: [1]
Jump to: 1





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts