Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reset button functionality

Status
Not open for further replies.

arravalli12

Programmer
May 3, 2005
62
US
I have a form and am updating only one text box value. I have a server side validation which will display error message and new value is displayed on text box when you hit update button and if there is any error.
Else it will update the record.
Now when error message appears, user wants to reset the value to original. Since I am giving server side validation error message, the reset button does not change to original values.
Is there any way, I can do that. Any help will be appreciated. I do not want to use client side validation..
Thanks

My code is:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include virtual="/Connections/DataCom_Server.asp" -->
<!--#include virtual="/common/HeaderDisplay.asp"-->
<!-- #include virtual="/common/PLCBsignin.asp" -->
<!-- #include virtual="/Common/SecurityCheck.asp" -->


<script language="JavaScript">
function setFocus()
{
FamilyCode2_update.FamilyCode.focus();
FamilyCode2_update.FamilyCode.select()
}
</script>
<script>
history.forward();
</script>

<%
dim CD_NO
CD_NO = request.querystring("code_no")
dim MM_abortEdit
MM_abortEdit = false
Dim Recordset1
Dim Recordset1_numRows
Set Recordset1 = Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection = MM_DataCom_Server_STRING
Recordset1.Source = "select CDE_NO,FAMILY_CDE from SYSUSR.FAMILY_CDE_REC where CDE_NO = " & CD_NO
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()
Recordset1_numRows = 0
%>
<%
If Request.form("Submit") <> "" Then
Dim CDE_NO,FAMILY_CDE
CDE_NO = Request.form("code_no")
FAMILY_CDE = Request.Form("FamilyCode")
FAMILY_CDE = trim(FAMILY_CDE)

if isnumeric(FAMILY_CDE) then %>
<% if instr(FAMILY_CDE,",")>0 OR instr(FAMILY_CDE,".")>0 or instr(FAMILY_CDE,"+")>0 or instr(FAMILY_CDE,"-")>0 then
MM_abortEdit= true
response.write "<font color=red><br>Error on Code Number-" & CDE_NO&". You entered- "&FAMILY_CDE&".(Please enter numbers between 10 and 989. This record is not updated)</font>"
%>
<% Elseif (FAMILY_CDE>=1 and FAMILY_CDE < 10) or FAMILY_CDE > 989 then
MM_abortEdit= true
response.write "<font color=red><br>Error on Code Number-" & CDE_NO&". You entered- "&FAMILY_CDE&".(Please enter numbers between 10 and 989. This record is not updated)</font>"

end if
else
MM_abortEdit= true
response.write "<font color=red><br>Error on Code Number-" & CDE_NO&". You entered-"&FAMILY_CDE&".(Please enter numbers. This record is not updated)</font>"
end if
'select case len(FAMILY_CDE)
'case "3"
'FAMILY_CDE = "0" & FAMILY_CDE
'case "2"
'FAMILY_CDE = "00" & FAMILY_CDE
'end select
' If (FAMILY_CDE Mod 10) = 0 Then
'response.write "<font color=red><br>Error on Code Number-" &CDE_NO&". You entered-"&FAMILY_CDE&".(Please enter numbers which should not end in zero. This record is not updated)</font>"
'MM_abortEdit = True
'end if
If (MM_abortEdit = false) Then
set Doupdate = Server.CreateObject("ADODB.Command")
Doupdate.ActiveConnection = MM_DataCom_Server_STRING
Doupdate.CommandText = "Update SYSUSR.FAMILY_CDE_REC Set FAMILY_CDE ="& FAMILY_CDE & ", CHNG_FLG = 'Y' WHERE CDE_NO= "&CDE_NO
'response.write Doupdate.CommandText
'response.write Doupdate1.CommandText
'response.end
Doupdate.CommandType = 1
Doupdate.CommandTimeout = 0
Doupdate.Prepared = true
Doupdate.Execute()
response.write " Record updated"
'Response.Redirect("familycode_Update.asp")
end if

end if

%>

<html>
<link rel="stylesheet" type="text/css" href="common/gen-Style2.css">
<style type="text/css">
<!--
.style1 {
color: #663300;
font-weight: bold;
}
-->
</style>
<body onload="setFocus();if(history.length>=0)history.go(+1)">
<%
if MM_abortEdit= true then
FAMILY_CDE = Request.Form("FamilyCode")
else
FAMILY_CDE = trim((Recordset1.Fields.Item("FAMILY_CDE").Value))
end if%>

<form ACTION="" METHOD="Post" name="FamilyCode2_update">
<p align="center"><span style="font-size: 10px"><a href=" PLCB Industry Partners Main Page</a></span></p>
<p align="center"><span style="font-size: 10px">
<a href="familycode_Update.asp"> Family Code:Individual Updates</a></span></p>
<table width="42%" border="1" cellpadding="5" cellspacing="0" align="center" bordercolor="#C8C8D2">
<tr bgcolor="#FFFDE1" class="table-categories">
<td width="50%" align="center"><span class="style1"><font face=Verdana size=1>Code Number</font></span></td>

<td width="50%"><span class="style1"><font face=Verdana size=1>Family Code</font></span></td>

</tr>

<tr bgcolor="#f0f0f0" class="table-data">
<% 'box1 = (Recordset1.Fields.Item("code_no").Value) %>
<td align="center"> <span class="newsLink newsLink"><%=(Recordset1.Fields.Item("CDE_NO").Value)%>
<input name="code_no" type = hidden value="<%=(Recordset1.Fields.Item("CDE_NO").Value)%>">
</span></td>
<td><input name="FamilyCode" type="text" value="<%=FAMILY_CDE%>" maxlength="3"></td>
</tr>

</table>
<div align="center">
<input name="submit" type="submit" value="Update" >
<input name="Reset" type="reset" value="Reset" >
</div>
</form>
</html>
<%
Recordset1.Close()
Set Recordset1 = Nothing
%>
 

I wonder about sending the "default" value down in a hidden field... and have a RESET button that is actually a submit button. This RESET submits the form (including the default value in the hidden text field) and re-delivers the page with the value of the hidden form element now in the value for the real form element.

It's totally not javascript... since I'm assuming you are looking for a solution that will work regardless of the client.

Let us know how you go! [smile]
Jeff

 

Of course... if you are fine with a javascript solution... use the reset button to merely copy the value(s) from the hidden text field(s) via an onclick on the button:
Code:
<input type="button" name="myReset" value="Reset" onclick="myReset()">
Of course... you can do all kinds of things in the myReset() function if you wanted to. Let us know if you want this kind of solution.

Cheers,
Jeff

 
I tried using myReset() but it does not work. May be I am not doing correctly..I am able to capture the hidden text field which is confirmed by response.write and response.end statement.

 

myReset() would be the name of a Javascript function that you would write.

Jeff

 
I have written the function but I am not able to capture the hidden field value.
inside function : I am writing
(form1.textname.value = trim(Request.form("hidden")).
this gives error...(syntax error)
 

You are trying to mix server-side with client-side scripting. Output the "hidden" value to the HTML page directly (<%=Request.form("hidden")%>).

Jeff

 
Thanks for the reply. I tried today and my program works perfectly.
Thanks once again all.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top