Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 372
  • Last Modified:

Duplicate value error handling before form is submitted

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
latzo4
Asked:
latzo4
  • 8
  • 5
  • 3
1 Solution
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
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
 
latzo4Author Commented:
Nothing is happening with that code
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
latzo4Author Commented:
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
 
latzo4Author Commented:
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
 
Shailesh15Commented:
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
 
Shailesh15Commented:
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
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
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
 
latzo4Author Commented:
<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
 
latzo4Author Commented:
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
 
Shailesh15Commented:
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
 
latzo4Author Commented:
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
 
latzo4Author Commented:
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
 
Shailesh15Commented:
OK call that part before submit in submitForm
*********************************
else{

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

}
}

***********************************
0
 
Shailesh15Commented:
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
 
latzo4Author Commented:
Thanks!, it all works like a charm
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 8
  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now