Link to home
Start Free TrialLog in
Avatar of latzo4
latzo4

asked on

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>
++++++++++++++++
Avatar of Big Monty
Big Monty
Flag of United States of America image

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.
Avatar of latzo4
latzo4

ASKER

Nothing is happening with that code
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.
Avatar of latzo4

ASKER

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.
Avatar of latzo4

ASKER

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.
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
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.
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.
Avatar of latzo4

ASKER

<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>
Avatar of latzo4

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of Shailesh15
Shailesh15

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of latzo4

ASKER

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>

Avatar of latzo4

ASKER

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"


OK call that part before submit in submitForm
*********************************
else{

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

}
}

***********************************
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">
Avatar of latzo4

ASKER

Thanks!, it all works like a charm