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.g et_GUID2.s electedind ex
guidID=document.frm_guid2. get_GUID2. options(ge tID).value
companyID=document.frm_gui d2.get_GUI D2.options (getID).te xt
//>dID=guidID & " - " & companyID
dID=guidID
document.frm_guid2.txt_gui d2.value=d ID
end sub
</script>
<SCRIPT LANGUAGE=javascript>
<!--
function submitForm()
{
document.frm_guid2.txt_gui d1.value = top.frames[0].document.frm _guid1.txt _guid1.val ue;
document.frm_guid2.submit( );
//-->
}
</SCRIPT>
<FORM NAME="frm_guid2" onsubmit="createTarget(thi s.target); javascript :submitFor m()" 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("O RGNAME").v alue%> </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>
++++++++++++++++
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.g
guidID=document.frm_guid2.
companyID=document.frm_gui
//>dID=guidID & " - " & companyID
dID=guidID
document.frm_guid2.txt_gui
end sub
</script>
<SCRIPT LANGUAGE=javascript>
<!--
function submitForm()
{
document.frm_guid2.txt_gui
document.frm_guid2.submit(
//-->
}
</SCRIPT>
<FORM NAME="frm_guid2" onsubmit="createTarget(thi
<input name="txt_guid1" value="" type="hidden">
<select name="get_GUID2" value="0" size=9 style="width:685px" onclick="vbscript:get_text
<%
Set adoRS2 = cmd2.Execute
Response.Write ""
End With
Set cmd2 = Nothing
While Not adoRS2.EOF
%>
<option value= <%=adoRS2.fields("orgid").
<%
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>
++++++++++++++++
ASKER
Nothing is happening with that code
sorry, use this as the if statement:
if (document.frm_guid2.txt_gu id1.value == document.frm_guid2.txt_gui d2.value) {
i was comparing the same field twice so naturally nothing would happen :)
B.D.
if (document.frm_guid2.txt_gu
i was comparing the same field twice so naturally nothing would happen :)
B.D.
ASKER
I script displays an alert message, however because i have:
<FORM NAME="frm_guid2" onsubmit="createTarget(thi s.target); javascript :submitFor m()" 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.
<FORM NAME="frm_guid2" onsubmit="createTarget(thi
after closing the javascript alert box it still procedes to 'merge.asp' how do i kill the action of the form.
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:submit Form()">
Replace the function
************************** ********** ***
<SCRIPT LANGUAGE=javascript>
<!--
function submitForm()
{
//change the frames id if you this page in other frame
//alert(top.frames[0].docu ment.frm_g uid1.txt_g uid1.value );
if( document.frm_guid1.otherID .value == top.frames[0].document.frm _guid1.txt _guid1.val ue){
alert("You can not select same in ......your error message");
}
else{
document.frm_guid1.otherID .value = top.frames[0].document.frm _guid1.txt _guid1.val ue;
document.frm_guid1.submit( );
}
}
//-->
</SCRIPT>
************************** ****
You can also use onsubmit event. instead of onclick
Submit button you need to change to
<INPUT type=button value=submit onclick="javascript:submit
Replace the function
**************************
<SCRIPT LANGUAGE=javascript>
<!--
function submitForm()
{
//change the frames id if you this page in other frame
//alert(top.frames[0].docu
if( document.frm_guid1.otherID
alert("You can not select same in ......your error message");
}
else{
document.frm_guid1.otherID
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:submit Form()">
Replace the function
************************** ********** ***
<SCRIPT LANGUAGE=javascript>
<!--
function submitForm()
{
if( document.frm_guid2.txt_gui d2.value == top.frames[0].document.frm _guid1.txt _guid1.val ue){
alert("You can not select same in ......your error message");
}
else{
document.frm_guid2.txt_gui d1.value = top.frames[0].document.frm _guid1.txt _guid1.val ue;
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.
here it is ...
Submit button you need to change to
<INPUT type=button value=submit onclick="javascript:submit
Replace the function
**************************
<SCRIPT LANGUAGE=javascript>
<!--
function submitForm()
{
if( document.frm_guid2.txt_gui
alert("You can not select same in ......your error message");
}
else{
document.frm_guid2.txt_gui
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(thi s.target); javascript :submitFor m()"
from your form tag and put the function createTarget() in the function i created:
function submitForm()
{
if (document.frm_guid2.txt_gu id1.value == document.frm_guid2.txt_gui d1.value) {
alert("txt_guid1 = txt_guid2, not allowed mister!");
return false;
} else {
createTarget();
document.frm_guid2.txt_gui d1.value = top.frames[0].document.frm _guid1.txt _guid1.val ue;
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.
onsubmit="createTarget(thi
from your form tag and put the function createTarget() in the function i created:
function submitForm()
{
if (document.frm_guid2.txt_gu
alert("txt_guid1 = txt_guid2, not allowed mister!");
return false;
} else {
createTarget();
document.frm_guid2.txt_gui
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.
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"> </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 "INTO" 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 .Connectio n")
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_IntellisearchComp anies"
.CommandType = adCmdStoredProc2
.Parameters.Append .CreateParameter("@UserID" , adGUID2, adParamInput2, 0, "{6FF5F8BD-26D8-42A9-9654- 3CA8021739 DA}")
.Parameters.Append .CreateParameter("@OrgName ", adVarWChar2, adParamInput2, 100,strData2)
.Parameters.Append .CreateParameter("@Relatio nshipIDs", adVarWChar2, adParamInput2, 4000)
.Parameters.Append .CreateParameter("@FilterS tatus", adInteger2, adParamInput2, 0, 0)
.Parameters.Append .CreateParameter("@Related OrgsOnly", 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.g et_GUID2.s electedind ex
guidID=document.frm_guid2. get_GUID2. options(ge tID).value
companyID=document.frm_gui d2.get_GUI D2.options (getID).te xt
dID=guidID
eID=companyID
document.frm_guid2.txt_gui d2.value=d ID
document.frm_guid2.txt_com pany2.valu e=eID
end sub
</script>
<SCRIPT LANGUAGE=javascript>
function submitForm()
{
document.frm_guid2.txt_gui d1.value = top.frames[0].document.frm _guid1.txt _guid1.val ue;
document.frm_guid2.txt_com pany1.valu e = top.frames[0].document.frm _guid1.txt _company1. value;
document.frm_guid2.submit( );
//-->
}
</SCRIPT>
<FORM NAME="frm_guid2" onsubmit="createTarget(thi s.target); javascript :submitFor m()" 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("O RGNAME").v alue%> [ <%=adoRS2("Street").value% >, &n bsp; <%=adoRS2("city").value%>, &nbs p; <%=adoRS2("state").value%> , &nb sp; <%=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>
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"> </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 "INTO" 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
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
strData2 = Request.QueryString("x2")
With cmd2
Set .ActiveConnection = cn2
.CommandText = "sfa_all_IntellisearchComp
.CommandType = adCmdStoredProc2
.Parameters.Append .CreateParameter("@UserID"
.Parameters.Append .CreateParameter("@OrgName
.Parameters.Append .CreateParameter("@Relatio
.Parameters.Append .CreateParameter("@FilterS
.Parameters.Append .CreateParameter("@Related
.Parameters.Append .CreateParameter("@OrgID",
.Parameters.Append .CreateParameter("@TraceUp
%>
<script language=vbscript>
sub get_text_index()
dim getID
getID=document.frm_guid2.g
guidID=document.frm_guid2.
companyID=document.frm_gui
dID=guidID
eID=companyID
document.frm_guid2.txt_gui
document.frm_guid2.txt_com
end sub
</script>
<SCRIPT LANGUAGE=javascript>
function submitForm()
{
document.frm_guid2.txt_gui
document.frm_guid2.txt_com
document.frm_guid2.submit(
//-->
}
</SCRIPT>
<FORM NAME="frm_guid2" onsubmit="createTarget(thi
<!-- 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"
<tr>
<td height="165" align="center"> <select name="get_GUID2" value="0" size=9 style="width:685px" onclick="vbscript:get_text
<%
Set adoRS2 = cmd2.Execute
End With
Set cmd2 = Nothing
While Not adoRS2.EOF
%>
<option value= <%=adoRS2.fields("orgid").
<%
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>
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.
- 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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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>
<script type="text/javascript">
function createTarget(t){
window.open("", t, "width=450,height=500, resize=no");
return true;
}
</script>
ASKER
Correction: the window DOES show up but these attributes do not work any more
"toolbar=no,width=450,heig ht=500,dir ectories=n o,status=n o,scrollba rs=no,resi ze=no,menu bar=no"
"toolbar=no,width=450,heig
OK call that part before submit in submitForm
************************** *******
else{
window.open("", "formtarget", "width=450,height=500");
document.frm_guid2.submit( );
}
}
************************** *********
**************************
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">
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">
ASKER
Thanks!, it all works like a charm
function submitForm()
{
document.frm_guid2.txt_gui
document.frm_guid2.submit(
}
to:
function submitForm()
{
if (document.frm_guid2.txt_gu
alert("txt_guid1 = txt_guid2, not allowed mister!");
return false;
} else {
document.frm_guid2.txt_gui
document.frm_guid2.submit(
}
}
B.D.