onsubmit problem

Results 1 to 2 of 2

Thread: onsubmit problem

  1. #1
    Linda Guest

    Default onsubmit problem

    When the submit button is pressed a Validate Fields function is called. If a field isn&#039t true, an alert message appears and instead of setting focus back to the field, my submit continues thru to the next page which displays an error. How do I not move forward to this next page.when a textfield had a problem, like being left blank. Here&#039s the code for the start of my function,the onsubmit and the code for the next page. Could it be that since I am telling it to go to the next page on action=update.asp, that it&#039ll do this regardless. I tried putting a return false after the onsubmit code but that only screws up one of my fields. Anyway let me know if you can make sense:<BR>&#060;form METHOD="POST" action="update.asp" onsubmit="ValidateFields()"&#062;<BR><BR>function ValidateFields() <BR>{ with(document.forms[0])<BR> { (!select()) return false;<BR> if(!TextBoxFields(email,"Email Address")) return false;<BR> if(!emailCheck(email.value)) return false;<BR> if(!TextBoxFields(submittedby,"Name")) return false;<BR> if(!TextBoxFields(comments,"Comments")) return false;<BR> if(!replaceChars(comments.value)) return false;<BR> }<BR> return true;}<BR><BR>UPDATE.ASP Page<BR><BR>&#060;% DIM cnupdate<BR>on error resume next &#039if you get an error go to next line of code<BR>Set cnupdate=server.CreateObject("ADODB.CONNECTION")<B R>cnupdate.Provider="MSDASQL"<BR>cnupdate.Open "reviews"<BR>cnupdate.Execute"Insert into reviews(sentby,thisdate,emailaddress,review,restau rantname) " &_<BR> "values(&#039"& Request.form("submittedby")&"&#039,&#039" & Request.form("=DATE()")&"&#039,&#039" & Request.form("email")&"&#039,&#039" & Request.form("comments")&"&#039,&#039" & Request.form("selection")&"&#039)"<BR> <BR>if err.number&#060;&#062;0 then<BR>response.write err.description<BR>response.redirect"http://www.jerseymenus.com/rejected2.htm" <BR>else<BR>response.redirect"http://www.jerseymenus.com/successful2.htm"<BR>end if <BR>%&#062;<BR><BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default Easy solution

    &nbsp;<BR>Your ValidateFields method properly returns true/false, but you aren&#039t passing that value on to the onSubmit logic. Just change this:<BR><BR>&#060;form METHOD="POST" action="update.asp" onsubmit="ValidateFields()"&#062;<BR><BR>to this:<BR><BR>&#060;form METHOD="POST" action="update.asp" onsubmit="return ValidateFields()"&#062;<BR><BR>(add in the keyword return there--as it is, you weren&#039t returning anything so onSubmit said "go for it")<BR><BR>Nice coding of the ValidateFields function, incidentally!<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts