Click to See Complete Forum and Search --> : form values
Consuelo
07-01-2003, 08:42 PM
because im using session variables i need to be able to reset input values to "" and keep values in input if submit is clicked
basically i need java script that will keep the users input values instead of deleting on submit
was trying for
function check()
{
document.frmJoinUs.lastname.value = <%=Session("LastName")%>
} but this didnt work
The code you posted looks like it would work fine. If you have an example of this online, may I see the link to better asisst you?
[J]ona
Consuelo
07-01-2003, 08:51 PM
heres the link but i think it will time out - probably cant be seen outside of the university..
what about my code - can i post that?
Consuelo
07-01-2003, 08:53 PM
http://140.159.223.211/6814u01/lab3/joinus.asp
Originally posted by Consuelo
heres the link but i think it will time out - probably cant be seen outside of the university..
what about my code - can i post that?
Apparently, I cannot view the link "outside of the university." So, yes, please post your code.
[J]ona
Consuelo
07-01-2003, 09:01 PM
i got rid of the "=" in last name so the reset button would work but now if the user clicks submit the values also dissapear thats why im trying to use javascript to redisplay the users input after the submit
<INPUT type="TEXT" name="firstname" size="20" MaxLength="20" value="<%=Session("FirstName")%>">
Last Name:<FONT color='#ff0000'>*</FONT>
<INPUT type="TEXT" name="lastname" size="20" MaxLength="20" value="<%Session("LastName")%>">
**************
<%@ language=VBScript %>
<%
option explicit
Response.Buffer = true
Response.Expires = 0
'on error resume next
'------------------------------------------------------------------------------
' file name JoinUs.asp
' Description :
' History:
' 2001-02-01 - HShi - created
'------------------------------------------------------------------------------
%>
<!--#INCLUDE FILE="../lib/ut_utility.asp"-->
<!--#INCLUDE FILE="./addDataToFile.inc"-->
<%
Dim f1
Dim strCheck1,strCheck2,strCheck3,strCheck4, strCheck, strReSelect
Dim strMessage
Call Initialisation
Const HTML_TEXTAREA_SIZE_LIMIT = 250
If UCase(trim(Request.Form("cmdSubmit"))) = "SUBMIT NOW" Then
Call AddFormData
'Do user input and business rule validation
If IsValidForm = False Then
strMessage = "<font color='#ff0000'><BR><b>Please review the following details before re-submitting the application form</b>." & _
strMessage & "<br></font>"
Else
addToTable()
strMessage = "<font color='GREEN'><b>Thank you for your application. You will receive a confirmation email.</b></font><BR><BR>"
strMessage = strMessage
%>
<!--#INCLUDE FILE="./createnewfile.inc"-->
<%
Dim fso,fn
Dim strFileName
strFileName = createnewfile
fn = Server.MapPath(".")
fn = fn & "\"
fn = fn & strFileName & ".htm"
Session ("fn") = "http://140.159.223.211/6814u01/lab3/" & strFileName & ".htm"
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set f1 = fso.CreateTextFile(fn, True)
addDataToFile()
Response.Redirect("./Acknowledgement.asp")
End If
End If
%>
<HTML>
<HEAD>
<TITLE>Join MyClub.com</TITLE>
<STYLE>
<!-- #include FILE="../includes/MyClub.css" -->
</STYLE>
<script language="JavaScript" src="../lib/mylab2.js">
<!--
function check()
{
document.frmJoinUs.lastname.value = <%=Session("LastName")%>
}
//-->
</script>
</HEAD>
<body bgcolor="#FFFFFF" onLoad="MM_preloadImages('../images/myclub_logo_magenta.gIf','../images/aboutus_over.gIf','../images/joinus_over.gIf','../images/contactus_over.gIf')" leftmargin="0" topmargin="0">
<!--#include FILE="../includes/myclub_menubar2.inc" -->
<CENTER><H2>Online Membership Application Form</H2></CENTER>
<P align="CENTER">
<%
If (UCase(trim(Request.Form("cmdSubmit"))) = "SUBMIT NOW" ) Then
%>
<table border="0" width="*" align="center">
<tr>
<td> </td>
<td align="left"><font color='#ff0000'>
<%=strMessage%>
</font><BR>
</td>
<td> </td>
</tr>
</table>
<%
End If
If UCase(trim(Request.Form("Reset"))) = "RESET" Then
Session.Abandon
Response.WriteLine("reset")
'Session("FirstName") = ""
'Session("LastName") = ""
'Session("Phone") = ""
'Session("Fax") = ""
'Session("Email") = ""
'Session("Mobile") = ""
'Session("message") = ""
'Session("Gender") = ""
'Session("Hobby1") = ""
'Session("Hobby2") = ""
'Session("Hobby3") = ""
'Session("Hobby4") = ""
'Session("Occupation") = ""
'Session("UserName") = ""
'Session("password") = ""
'Session("password2") = ""
End If
%>
You can choose your favorite background color:<BR>
<BUTTON onClick="document.bgColor='white'"> WHITE </BUTTON>
<BUTTON onClick="document.bgColor='red'"> RED </BUTTON>
<BUTTON onClick="document.bgColor='green'"> GREEN </BUTTON>
<BUTTON onClick="document.bgColor='blue'"> BLUE </BUTTON>
<BUTTON onClick="document.bgColor='yellow'"> YELLOW </BUTTON>
<BUTTON onClick="var bg = prompt('Please enter your favorite color' , 'custom');document.bgColor=bg"> CUSTOM </BUTTON>
<BR>
<form method="post" action="<%=Request.ServerVariables("SCRIPT_NAME")%>"
name="frmJoinUs" onSubmit="return confirmSubmit();">
<TABLE>
<TR align = "LEFT"><B>Fields marked with "<FONT color='#ff0000'>*</FONT>" are compulsory<B><TR>
<TR>
<TD align="RIGHT">First Name:<FONT color='#ff0000'>*</FONT>
</TD>
<TD>
<INPUT type="TEXT" name="firstname" size="20" MaxLength="20" value="<%=Session("FirstName")%>">
Last Name:<FONT color='#ff0000'>*</FONT>
<INPUT type="TEXT" name="lastname" size="20" MaxLength="20" value="<%Session("LastName")%>">
</TD>
</TR>
<TR>
<TD align="RIGHT">
Phone:<FONT color='#ff0000'>*</FONT>
</TD>
<TD colspan = "2">
<INPUT type="TEXT" name="phone" size="15" MaxLength="10" value="<%Session("Phone")%>" ID="Text1">
Fax:<INPUT type="TEXT" name="fax" size="15" MaxLength="10" value="<%Session("Fax")%>">
Mobile:<INPUT type="TEXT" name="mobile" size="15" MaxLength="10" value="<%Session("Mobile")%>">
</TD>
</TR>
<TR>
<TD align="RIGHT">E-Mail address:<FONT color='#ff0000'>*</FONT></TD>
<TD colspan = "2"><INPUT type="TEXT" name="email" size="30" MaxLength=30 value="<%Session("Email")%>"><TD>
</TR>
<%
strReSelect = Session("Gender")
If not len(trim(strReSelect)) > 0 then
strReSelect = ""
end If
%>
<TR>
<TD align="RIGHT">Gender:</TD>
<TD><INPUT type="RADIO" name="gender" value="Male"<%'ut_Checked("Male", strReSelect)%>>Male
<INPUT type="RADIO" name="gender" value="Female"<%'ut_Checked("Female", strReSelect)%>>Female</TD>
</TR>
<TR>
<TD align="RIGHT">Hobbies:</TD><TD>
<%
strCheck1 = Session("hobby1")
If not len(trim(strCheck1)) > 0 then
strCheck1 = ""
end If
strCheck2 = Session("hobby2")
If not len(trim(strCheck2)) > 0 then
strCheck2 = ""
end If
strCheck3 = Session("hobby3")
If not len(trim(strCheck3)) > 0 then
strCheck3 = ""
end If
strCheck4 = Session("hobby4")
If not len(trim(strCheck4)) > 0 then
strCheck4 = ""
end If
%>
<INPUT type=CHECKBOX name="hobby1" value="Basketball" <%'ut_checked("Basketball", strCheck1)%>> Basketball
<INPUT type=CHECKBOX name="hobby2" value="Golf" <%'ut_checked("Golf", strCheck2)%>> Golf
<INPUT type=CHECKBOX name="hobby3" value="Swimming" <%'ut_checked("Swimming", strCheck3)%>> Swimming
<INPUT type=CHECKBOX name="hobby4" value="Tennis" <%'ut_checked("Tennis", strCheck4)%>> Tennis
</TD>
</TR>
<%
strReSelect = Session("Occupation")
If not len(trim(strReSelect)) > 0 then
strReSelect = ""
end If
%>
<TR>
<TD align="RIGHT">Occupation:</TD>
<TD><SELECT name="Occupation">
<OPTION value="" <%'ut_Selected("", strReSelect)%>>[SELECT occupation]
<OPTION value="Executive" <%'ut_Selected("Executive", strReSelect)%>>Executive
<OPTION value="Professional" <%'ut_Selected("Professional", strReSelect)%>>Professional
<OPTION value="Academic" <%'ut_Selected("Academic", strReSelect)%>>Academic
<OPTION value="Technician" <%'ut_Selected("Technician", strReSelect)%>>Technician
<OPTION value="Other" <%'ut_Selected("Other", strReSelect)%> >Other
</SELECT>
</TD>
</TR>
<TR>
<TD align="RIGHT">Message (No more than 200 characters):</TD>
<TD><TEXTAREA name="message" cols="30" rows="4" ><%Session("message")%></TEXTAREA><TD>
</TR>
<TR><TD colspan=3><hr size=0></TD></TR>
<TR>
<TD align="RIGHT">Preferred username:<FONT color='#ff0000'>*</FONT></TD>
<td>
<INPUT type=text name="UserName" size=20 maxlength=20 value="<%Session("UserName")%>">
</TD>
</TR>
<TR>
<TD align="RIGHT">Password:<FONT color='#ff0000'>*</FONT></TD>
<TD><INPUT type=password name="password" size=20 maxlength=20 value="<%Session("password")%>"></TD>
</TR>
<TR>
<TD align="RIGHT">Confirm Password:<FONT color='#ff0000'>*</FONT></TD><td >
<INPUT type=password name="password2" size=20 maxlength=20 value="<%Session("password2")%>"></TD>
</TR>
<TR><TD colspan=3><hr size=0></TD></TR>
</TABLE>
<TABLE align="right">
<TR>
<TD><INPUT type="SUBMIT" name="cmdSubmit" value=" Submit Now " onClick = "check()" onClick = "messageFunction()"></TD>
<TD><INPUT type="Reset" name = "Reset" value="Reset" id=Reset>
</TD>
<TD><FONT color='#ff0000'>**Warning: This button will delete all your input!</FONT>
</TR>
</TABLE>
</FORM>
</P>
</BODY>
</HTML>
<%
Sub Initialisation
strCheck1 = ""
strCheck2 = ""
strCheck3 = ""
strCheck4 = ""
strCheck = ""
strReSelect = ""
strMessage = ""
End Sub
Sub AddFormData
Session("FirstName") = trim(Request.Form("FirstName"))
Session("LastName") = trim(Request.Form("LastName"))
Session("Phone") = trim(Request.Form("Phone"))
Session("Fax") = trim(Request.Form("Fax"))
Session("Email") = trim(Request.Form("Email"))
Session("Mobile") = trim(Request.Form("Mobile"))
Session("message") = trim(Request.Form("message"))
Session("Gender") = trim(Request.Form("Gender"))
Session("Hobby1") = trim(Request.Form("Hobby1"))
Session("Hobby2") = trim(Request.Form("Hobby2"))
Session("Hobby3") = trim(Request.Form("Hobby3"))
Session("Hobby4") = trim(Request.Form("Hobby4"))
Session("Occupation") = trim(Request.Form("Occupation"))
Session("UserName") = trim(Request.Form("UserName"))
Session("password") = trim(Request.Form("password"))
Session("password2") = trim(Request.Form("password2"))
End Sub
Function addToTable ()
Dim strCon, Con, strSQL, strSQL1, strSQL2
adds data to the database
End Function
Function IsValidForm()
IsValidForm = True
this function does server side validation
End Function %>
Try putting it in quotes, like this:
function check()
{
document.frmJoinUs.lastname.value = "<%=Session("LastName")%>";
}
[J]ona
Consuelo
07-01-2003, 09:10 PM
that didnt work :)
Maybe apostrophes...
function check()
{
document.frmJoinUs.lastname.value = '<%=Session("LastName")%>';
}
[J]ona
Consuelo
07-01-2003, 09:47 PM
thanks for your help
i was trying to add aditionaly functionality to an assignment but its due today so i think ill leave it
hope u have a good day :)
Consuelo
Sorry, you couldn't get it to work.
[J]ona