Solved

Duplicate value error handling before form is submitted

Posted on 2004-04-07
16
357 Views
Last Modified: 2008-02-01
How do i hide the submit button on this current form or keep the user form proceding if the "txt_guid1" is equal to "txt_guid2" in the below code...the rule is that there cannot be duplicate companies selected.

Do i put some data handling in the vbscript or javascript or form, how do i do this?

++++++++++++++++++++++++++++++
<script type="text/javascript">
function createTarget(t){
window.open("", t, "width=450,height=500");
return true;
}
</script>

...Connection information
...stored proc is run

<script language=vbscript>
sub get_text_index()
dim getID
    getID=document.frm_guid2.get_GUID2.selectedindex
    guidID=document.frm_guid2.get_GUID2.options(getID).value
    companyID=document.frm_guid2.get_GUID2.options(getID).text
    //>dID=guidID & " - " & companyID
     dID=guidID
    document.frm_guid2.txt_guid2.value=dID
end sub
</script>
<SCRIPT LANGUAGE=javascript>
<!--
function submitForm()
{
      document.frm_guid2.txt_guid1.value = top.frames[0].document.frm_guid1.txt_guid1.value;
      document.frm_guid2.submit();  
//-->
}
</SCRIPT>
<FORM NAME="frm_guid2" onsubmit="createTarget(this.target);javascript:submitForm()" target="formtarget"  action="merge.asp" method="post">
<input name="txt_guid1" value="" type="hidden">
<select name="get_GUID2" value="0" size=9 style="width:685px" onclick="vbscript:get_text_index()">
<%
Set adoRS2 = cmd2.Execute
Response.Write ""
End With
Set cmd2 = Nothing
While Not adoRS2.EOF
%>
<option value= <%=adoRS2.fields("orgid").value%>><%=adoRS2("ORGNAME").value%> </option>
<%
Response.Write "<br>"
adoRS2.MoveNext
Wend
%>
</select><input type="submit" value=" Merge Selected" name="B1" >
<input type="txt_var2" name="txt_guid2" style="width:280px">
 </FORM>
++++++++++++++++
0
Comment
Question by:latzo4
  • 8
  • 5
  • 3
16 Comments
 
LVL 32

Expert Comment

by:Big Monty
Comment Utility
change:
function submitForm()
{
     document.frm_guid2.txt_guid1.value = top.frames[0].document.frm_guid1.txt_guid1.value;
     document.frm_guid2.submit();  
}
to:
function submitForm()
{
if (document.frm_guid2.txt_guid1.value == document.frm_guid2.txt_guid1.value) {
     alert("txt_guid1 = txt_guid2, not allowed mister!");
     return false;
} else {
     document.frm_guid2.txt_guid1.value = top.frames[0].document.frm_guid1.txt_guid1.value;
     document.frm_guid2.submit();  
}
}

B.D.
0
 

Author Comment

by:latzo4
Comment Utility
Nothing is happening with that code
0
 
LVL 32

Expert Comment

by:Big Monty
Comment Utility
sorry, use this as the if statement:
if (document.frm_guid2.txt_guid1.value == document.frm_guid2.txt_guid2.value) {

i was comparing the same field twice so naturally nothing would happen :)

B.D.
0
 

Author Comment

by:latzo4
Comment Utility
I script displays an alert message, however because i have:

<FORM NAME="frm_guid2" onsubmit="createTarget(this.target);javascript:submitForm()" target="formtarget"  action="merge.asp" method="post">


after closing the javascript alert box it still procedes to 'merge.asp'  how do i kill the action of the form.
0
 

Author Comment

by:latzo4
Comment Utility
Also, it must be holding it in memory.  If i close the alert box and select a different company so that they do not match, It still displays the alert.
0
 
LVL 10

Expert Comment

by:Shailesh15
Comment Utility
I had posted this to your original thrread...

Submit button you need to change to
<INPUT type=button value=submit onclick="javascript:submitForm()">

Replace the function
***************************************
<SCRIPT LANGUAGE=javascript>
<!--
function submitForm()
{
//change the frames id if you this page in other frame
//alert(top.frames[0].document.frm_guid1.txt_guid1.value);
if( document.frm_guid1.otherID.value == top.frames[0].document.frm_guid1.txt_guid1.value){
alert("You can not select same in ......your error message");
}
else{
 document.frm_guid1.otherID.value = top.frames[0].document.frm_guid1.txt_guid1.value;
 document.frm_guid1.submit();  
}
}
//-->
</SCRIPT>
******************************

You can also use onsubmit event. instead of onclick
0
 
LVL 10

Expert Comment

by:Shailesh15
Comment Utility
oops I did not see that you have changed the control  names.

here it is ...
Submit button you need to change to
<INPUT type=button value=submit onclick="javascript:submitForm()">

Replace the function
***************************************
<SCRIPT LANGUAGE=javascript>
<!--
function submitForm()
{

if( document.frm_guid2.txt_guid2.value == top.frames[0].document.frm_guid1.txt_guid1.value){
      alert("You can not select same in ......your error message");
}
else{
     document.frm_guid2.txt_guid1.value = top.frames[0].document.frm_guid1.txt_guid1.value;
     document.frm_guid2.submit();  

}
}
//-->
</SCRIPT>
******************************

You can also try to kill submission by validating onsubmit. But it gave me same error as you have expalined.. posting after alert with duplicate values.
0
 
LVL 32

Expert Comment

by:Big Monty
Comment Utility
take out
onsubmit="createTarget(this.target);javascript:submitForm()"
from your form tag and put the function createTarget() in the function i created:
function submitForm()
{
if (document.frm_guid2.txt_guid1.value == document.frm_guid2.txt_guid1.value) {
     alert("txt_guid1 = txt_guid2, not allowed mister!");
     return false;
} else {
     createTarget();
     document.frm_guid2.txt_guid1.value = top.frames[0].document.frm_guid1.txt_guid1.value;
     document.frm_guid2.submit();  
}
}

then, on your submit button, add an onclick function that will call the above function. since i havent seen your full code, its hard for me to work out these problems. if you post it, i will get it working for you if the above suggestion doesn't work.

B.D.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:latzo4
Comment Utility
<script type="text/javascript">
function createTarget(t){
window.open("", t, "width=450,height=500");
return true;
}
</script>
</head>
<table width="99%" height="365" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="44%" height="34" valign="top">
      <form method="get" action="m_into.asp">
        <table width="700" border="0" cellpadding="0" cellspacing="1" bgcolor="#0000FF" align="center">
          <tr>
            <td width="100%"><table width="100%" border="0" cellpadding="0" cellspacing="0" bordercolor="#990066" bgcolor="#FFFFFF">
                <tr>
                  <td width="9%" height="32" align="center">&nbsp; </td>
                  <td width="37%" align="left"><input type=text style="width:170px" value=""<%= strSearch2 %>"" name="x2">
                    <input name="submit2" type=submit value="Search"></td>
                  <td width="54%" align="left"><font color="#000099" size="2" face="Arial, Helvetica, sans-serif"><strong>STEP
                    2. Select &quot;INTO&quot; Company Record</strong></font></td>
                </tr>
              </table></td>
          </tr>
        </table>
      </form></td>
  </tr>
  <tr>
    <td height="328" valign="top">
      <%
Dim strSearch2
Dim cn2
Dim cmd2
Dim rs2
Dim adCmdStoredProc2
Dim adParamInput2
Dim adParamOutput2
Dim adInteger2
Dim adVarChar2
Dim adVarWChar2
Dim adGUID2
Dim adBoolean2
Dim adParamReturnValue2
Dim adoField2
Dim adoRS2
adCmdStoredProc2 = 4
adParamInput2 = 1
adParamOutput2 = 2
adInteger2 = 3
adVarChar2 = 200
adVarWChar2 = 202
adGUID2 = 72
adBoolean2 = 11
adParamReturnValue2 = 4

IF Request.QueryString("x2") <>"" then
Set cn2 = Server.CreateObject("ADODB.Connection")
        cn2.Open "Provider=SQLOLEDB;Data Source=zzzz;" _
            & "Initial Catalog=zzzzz;User Id=sa;Password=;" _
            & "Connect Timeout=15;Network Library=dbmssocn;"
Set cmd2 = Server.CreateObject("ADODB.Command")
strData2 = Request.QueryString("x2")
With cmd2
   Set .ActiveConnection = cn2
   .CommandText = "sfa_all_IntellisearchCompanies"
   .CommandType = adCmdStoredProc2
   .Parameters.Append .CreateParameter("@UserID", adGUID2, adParamInput2, 0, "{6FF5F8BD-26D8-42A9-9654-3CA8021739DA}")
   .Parameters.Append .CreateParameter("@OrgName", adVarWChar2, adParamInput2, 100,strData2)
   .Parameters.Append .CreateParameter("@RelationshipIDs", adVarWChar2, adParamInput2, 4000)
   .Parameters.Append .CreateParameter("@FilterStatus", adInteger2, adParamInput2, 0, 0)
   .Parameters.Append .CreateParameter("@RelatedOrgsOnly", adBoolean2, adParamInput2, 0)
   .Parameters.Append .CreateParameter("@OrgID", adGUID2, adParamInput2, 0)
   .Parameters.Append .CreateParameter("@TraceUp", adBoolean2, adParamInput2, 0)
%>
<script language=vbscript>
sub get_text_index()
dim getID
    getID=document.frm_guid2.get_GUID2.selectedindex
    guidID=document.frm_guid2.get_GUID2.options(getID).value
    companyID=document.frm_guid2.get_GUID2.options(getID).text

     dID=guidID
       eID=companyID
    document.frm_guid2.txt_guid2.value=dID
      document.frm_guid2.txt_company2.value=eID
end sub
</script>
 
<SCRIPT LANGUAGE=javascript>

function submitForm()
{
document.frm_guid2.txt_guid1.value = top.frames[0].document.frm_guid1.txt_guid1.value;
 document.frm_guid2.txt_company1.value = top.frames[0].document.frm_guid1.txt_company1.value;
 document.frm_guid2.submit();  
//-->
}
</SCRIPT>

      <FORM NAME="frm_guid2" onsubmit="createTarget(this.target);javascript:submitForm()" target="formtarget"  action="merge.asp" method="post">
        <!-- New hidden field-->
        <input name="txt_guid1" value="" type="hidden">
            <input name="txt_company1" value="" type="hidden">
        <table width="700" border="0" cellpadding="0" cellspacing="1" bgcolor="#0000FF" align="center">
          <tr>
            <td width="700" height="165"align="center"><table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#FFFFFF">
                <tr>
                  <td height="165" align="center"> <select name="get_GUID2" value="0" size=9 style="width:685px" onclick="vbscript:get_text_index()">
                      <%
Set adoRS2 = cmd2.Execute
End With
Set cmd2 = Nothing
While Not adoRS2.EOF

%>
<option value= <%=adoRS2.fields("orgid").value%>><%=adoRS2("ORGNAME").value%> &nbsp;&nbsp; [  <%=adoRS2("Street").value%>,&nbsp;&nbsp; <%=adoRS2("city").value%>,&nbsp;&nbsp; <%=adoRS2("state").value%>,&nbsp;&nbsp; <%=adoRS2("zip").value%> ]</option>
<%
Response.Write "<br>"
adoRS2.MoveNext
Wend
%>
  </select></td>
                </tr>
              </table></td>
          </tr>
        </table>
        <p> </p>
        <table width="300" border="0" cellspacing="0" cellpadding="0" align="center" height="20">
          <tr>
            <td> <div align="center">
                <p>
                  <input type="submit" value="Merge Selected" name="B1" >
                  <input type="txt_var3" name="txt_guid2" style="width:280px">
                <input type="txt_var4" name="txt_company2" style="width:280px"></p>
                </div></td>
          </tr>
        </table>
      </FORM>

      <%
Set adoRS2 = adoRS2.NextRecordset
Set adoRS2 = Nothing
cn2.Close
Set cn2 = Nothing
End if
%>
    </td>
  </tr>
</table>
0
 

Author Comment

by:latzo4
Comment Utility
Yeah the above suggestion didn't work. So i posted the original

- the message box appears, but it still continues to the merge.asp form.
if i put the message on the click event it still continues to the merg.asp form.

- the first time around the message doesn't show up, after slecting from the two list bpxes again then the message shows up

Note: the other listbox that contains 'txt_guid1' is on another asp and passed to this page, its pretty much the identical code but without the submit button logic.


...i think a server side form validation is the way to go but don't really know how to do it.
0
 
LVL 10

Accepted Solution

by:
Shailesh15 earned 400 total points
Comment Utility
Back up your ASP before proceeding!...

***************************************
<script type="text/javascript">
function createTarget(t){
window.open("", t, "width=450,height=500");
return true;
}
</script>
<SCRIPT LANGUAGE=javascript>
<!--
function submitForm()
{
document.frm_guid2.txt_guid1.value = top.frames[0].document.frm_guid1.txt_guid1.value;
if( document.frm_guid2.txt_guid2.value == document.frm_guid2.txt_guid1.value){
      alert("You can not select same in ......your error message");
}
else{

     document.frm_guid2.submit();  

}
}
//-->
</SCRIPT>

</head>
<table width="99%" height="365" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="44%" height="34" valign="top">
      <form method="get" action="m_into.asp">
        <table width="700" border="0" cellpadding="0" cellspacing="1" bgcolor="#0000FF" align="center">
          <tr>
            <td width="100%"><table width="100%" border="0" cellpadding="0" cellspacing="0" bordercolor="#990066" bgcolor="#FFFFFF">
                <tr>
                  <td width="9%" height="32" align="center">&nbsp; </td>
                  <td width="37%" align="left"><input type=text style="width:170px" value=""<%= strSearch2 %>"" name="x2">
                    <input name="submit2" type=submit value="Search"></td>
                  <td width="54%" align="left"><font color="#000099" size="2" face="Arial, Helvetica, sans-serif"><strong>STEP
                    2. Select &quot;INTO&quot; Company Record</strong></font></td>
                </tr>
              </table></td>
          </tr>
        </table>
      </form></td>
  </tr>
  <tr>
    <td height="328" valign="top">
      <%
Dim strSearch2
Dim cn2
Dim cmd2
Dim rs2
Dim adCmdStoredProc2
Dim adParamInput2
Dim adParamOutput2
Dim adInteger2
Dim adVarChar2
Dim adVarWChar2
Dim adGUID2
Dim adBoolean2
Dim adParamReturnValue2
Dim adoField2
Dim adoRS2
adCmdStoredProc2 = 4
adParamInput2 = 1
adParamOutput2 = 2
adInteger2 = 3
adVarChar2 = 200
adVarWChar2 = 202
adGUID2 = 72
adBoolean2 = 11
adParamReturnValue2 = 4

IF Request.QueryString("x2") <>"" then
Set cn2 = Server.CreateObject("ADODB.Connection")
       cn2.Open "Provider=SQLOLEDB;Data Source=zzzz;" _
          & "Initial Catalog=zzzzz;User Id=sa;Password=;" _
          & "Connect Timeout=15;Network Library=dbmssocn;"
Set cmd2 = Server.CreateObject("ADODB.Command")
strData2 = Request.QueryString("x2")
With cmd2
   Set .ActiveConnection = cn2
   .CommandText = "sfa_all_IntellisearchCompanies"
   .CommandType = adCmdStoredProc2
   .Parameters.Append .CreateParameter("@UserID", adGUID2, adParamInput2, 0, "{6FF5F8BD-26D8-42A9-9654-3CA8021739DA}")
   .Parameters.Append .CreateParameter("@OrgName", adVarWChar2, adParamInput2, 100,strData2)
   .Parameters.Append .CreateParameter("@RelationshipIDs", adVarWChar2, adParamInput2, 4000)
   .Parameters.Append .CreateParameter("@FilterStatus", adInteger2, adParamInput2, 0, 0)
   .Parameters.Append .CreateParameter("@RelatedOrgsOnly", adBoolean2, adParamInput2, 0)
   .Parameters.Append .CreateParameter("@OrgID", adGUID2, adParamInput2, 0)
   .Parameters.Append .CreateParameter("@TraceUp", adBoolean2, adParamInput2, 0)
%>
<script language=vbscript>
sub get_text_index()
dim getID
    getID=document.frm_guid2.get_GUID2.selectedindex
    guidID=document.frm_guid2.get_GUID2.options(getID).value
    companyID=document.frm_guid2.get_GUID2.options(getID).text

     dID=guidID
      eID=companyID
    document.frm_guid2.txt_guid2.value=dID
     document.frm_guid2.txt_company2.value=eID
end sub
</script>
 

      <FORM NAME="frm_guid2" onsubmit="createTarget(this.target);" target="formtarget"  action="merge.asp" method="post">
        <!-- New hidden field-->
       
        <input name="txt_guid1" value="" type="hidden">
          <input name="txt_company1" value="" type="hidden">
        <table width="700" border="0" cellpadding="0" cellspacing="1" bgcolor="#0000FF" align="center">
          <tr>
            <td width="700" height="165"align="center"><table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#FFFFFF">
                <tr>
                  <td height="165" align="center"> <select name="get_GUID2" value="0" size=9 style="width:685px" onclick="vbscript:get_text_index()">
                      <%
Set adoRS2 = cmd2.Execute
End With
Set cmd2 = Nothing
While Not adoRS2.EOF

%>
<option value= <%=adoRS2.fields("orgid").value%>><%=adoRS2("ORGNAME").value%> &nbsp;&nbsp; [  <%=adoRS2("Street").value%>,&nbsp;&nbsp; <%=adoRS2("city").value%>,&nbsp;&nbsp; <%=adoRS2("state").value%>,&nbsp;&nbsp; <%=adoRS2("zip").value%> ]</option>
<%
Response.Write "<br>"
adoRS2.MoveNext
Wend
%>
  </select></td>
                </tr>
              </table></td>
          </tr>
        </table>
        <p> </p>
        <table width="300" border="0" cellspacing="0" cellpadding="0" align="center" height="20">
          <tr>
            <td> <div align="center">
                <p>
                <INPUT type=button value="Merge Selected" name="B1" onclick="javascript:submitForm()">
                 
                  <input type="txt_var3" name="txt_guid2" style="width:280px">
                <input type="txt_var4" name="txt_company2" style="width:280px"></p>
                </div></td>
          </tr>
        </table>
      </FORM>

      <%
Set adoRS2 = adoRS2.NextRecordset
Set adoRS2 = Nothing
cn2.Close
Set cn2 = Nothing
End if
%>
    </td>
  </tr>
</table>

*************************
0
 

Author Comment

by:latzo4
Comment Utility
yes that works! however this part does not work anymore... the first part:

<script type="text/javascript">
function createTarget(t){
window.open("", t, "width=450,height=500, resize=no");
return true;
}
</script>

0
 

Author Comment

by:latzo4
Comment Utility
Correction: the window DOES show up but these attributes do not work any more

"toolbar=no,width=450,height=500,directories=no,status=no,scrollbars=no,resize=no,menubar=no"


0
 
LVL 10

Expert Comment

by:Shailesh15
Comment Utility
OK call that part before submit in submitForm
*********************************
else{

     window.open("", "formtarget", "width=450,height=500");
     document.frm_guid2.submit();  

}
}

***********************************
0
 
LVL 10

Expert Comment

by:Shailesh15
Comment Utility
call that part with those parameters.

window.open("", "formtarget", "width=450, height=500,  menubar=no, status=no, location=no, toolbar=no, scrollbars=no, resizable=yes");

also remove that function call from form onsubmit

<FORM NAME="frm_guid2"  target="formtarget"  action="merge.asp" method="post">
0
 

Author Comment

by:latzo4
Comment Utility
Thanks!, it all works like a charm
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now