|
harris -> 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
|
|
|
|