PDA

Click to See Complete Forum and Search --> : client side validation


scottr
Jul 12th, 2000, 06:31 PM
does anyone have an example of the following:

javascript validation on a form

if successfull call aspcode to process the form into a database. I have the javascript working but i cant get it to process correctly. Any example would be great

dvst8
Jul 13th, 2000, 09:11 AM
pretty busy at work right now, so dont have time to write up the code for you, but if you form validation is working, just do the following:



<SCRIPT LANGUAGE=javascript>
<!--

function checkform(){

//do you checking here
if successful
document.form1.submit()

}


-->

</SCRIPT>


do you need more than this?
dvst8

scottr
Jul 13th, 2000, 11:09 AM
I have the javascript working fine. It does all the validation..


function validPass(inPass) {
if (inPass == "") {
return true
}
if (inPass.length >=6) {
return true
}

return false
}



function submitIt(JoinForm) {

if (JoinForm.oldPass.value == "") {
alert("Please enter password.")
JoinForm.oldPass.focus()
return false
}

if (JoinForm.newPass.value == "") {
alert("Please enter your password.")
JoinForm.newPass.focus()
JoinForm.newPass.select()
return false

}


if (!validPass(JoinForm.newPass.value)) {
alert("Your password must be at least 6 characters.")
JoinForm.newPass.focus()
JoinForm.newPass.select()
return false
}

if (JoinForm.confirmNewPass.value == "") {
alert("Please enter your password.")
JoinForm.confirmNewPass.focus()
JoinForm.confirmNewPass.select()
return false

}
if (JoinForm.confirmNewPass.value != JoinForm.newPass.value) {
alert("The passwords must be the same.")
JoinForm.confirmNewPass.focus()
JoinForm.confirmNewPass.select()
return false
}

document.frmPass.submit();



But the form is not bing called correctly. I sort of solved it by posting to another form that does the procesing but why cant i post to the same form?

noone
Jul 13th, 2000, 01:55 PM
Is the submitIt(JoinForm)function being called from frmPass's onSubmit event? If it is then your last line: document.frmPass.submit();
would not be allowed because it would endlessly loop.

scottr
Jul 13th, 2000, 04:16 PM
i am calling it in the following manner:

<form onSubmit="return submitIt(this)" method="post" action="changePass.asp" id="frmPass" name="frmPass">

i have the following aspcode that i am trying to process at the beginning of the page

<%Sub ChangePass()
on error goto 0
dim dbconn
dim strNewPass
dim strLoginCheck
dim rstUpdate
Dim qryUpdate
dim blnSuccess

Set dbConn= Server.CreateObject("ADODB.Connection")
dbConn.Open connString
'student
set rstUpdate = Server.CreateObject("ADODB.Recordset")


strLoginCheck="Y"


qryUpdate="UPDATE table SET variable='"& Request.form("variable") &"', variable='"& variable & "' WHERE variable = " & session("varaible")

set rstUpdate = dbConn.Execute(qryUpdate)
set rstupdate=dbconn.Execute("standard sql))
if not rstUpdate.EOF then
if rstUpdate("LOGIN_CHECK")="Y" then
closers(dbConn)
closeRS(rstUpdate)
Response.Redirect("goodpage.asp")
else
closers(dbConn)
closeRS(rstUpdate)
Response.Redirect("badpage.asp")
end if
end if
End Sub

If Request.Form("Submit1") = "GO" Then
call changePass()
end if%>


right now when i click the go button it works through the javascript but doesnt touch the asp code. But when i post to another page to process works great. I change the bottom of the java script to :

return false
}
return true'if successfull
}
i thought that might be a loop like you guys said.