?
Solved

Duplicate value error handling before form is submitted

Posted on 2004-04-07
16
Medium Priority
?
366 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 5
  • 3
16 Comments
 
LVL 33

Expert Comment

by:Big Monty
ID: 10778821
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
ID: 10779269
Nothing is happening with that code
0
 
LVL 33

Expert Comment

by:Big Monty
ID: 10779279
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:latzo4
ID: 10779333
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
ID: 10779380
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
ID: 10780027
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
ID: 10780133
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 33

Expert Comment

by:Big Monty
ID: 10783752
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
 

Author Comment

by:latzo4
ID: 10785569
<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
ID: 10785627
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 1600 total points
ID: 10785687
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
ID: 10785859
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
ID: 10785957
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
ID: 10785979
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
ID: 10786025
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
ID: 10786816
Thanks!, it all works like a charm
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

801 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