Help required..

Results 1 to 2 of 2

Thread: Help required..

  1. #1
    Urgent Guest

    Default Help required..

    I am writing an application in which the my form is created based on the values in a table in a database where a certain flag is set if a certain field is to be displayed.<BR><BR>I need to do client-side javascript validation for the same form.<BR><BR>I am not sure how to do this as I am not sure while coding which fields will be displayed and which will not.<BR><BR>Does anyone have any suggestion?<BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default Building validation *with* form...

    Pretty simple: as you create the form fields, *also* create the JS validation code. Put one or the other into a string, instead of dumping it directly to the screen, and then output the entire string at an appropriate spot in the page.<BR><BR>*VERY* simple example:<BR><BR>&#060;FORM .... onSubmit="return validate(this);" ... &#062;<BR>&#060;%<BR>vcode = "function validate(theForm) {" & vbNewline<BR>vcode = vcode & "&nbsp;&nbsp;&nbsp;&nbsp;return ( true" & vbNewline<BR><BR>If dbField("whatever") = "somevalue" Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;Response.Write "&#060;INPUT Type=Text Name=whatever value=&#039" & dbField("whatever") & "&#039&#062;"<BR>vcode = vcode & "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& amp;&amp; isValidTextField(theForm.whatever)" & vbNewLine<BR>...<BR>... do other fields ...<BR>...<BR>vcode = vcode & "); }" & vbNewLine<BR>...<BR>&#060;/FORM&#062; <BR>&#060;SCRIPT Language=JavaScript&#062;<BR>&#060;% = vcode %&#062;<BR>&#060;/SCRIPT&#062;<BR>...<BR><BR>*********************** **<BR><BR>See the idea? If I have precoded various kinds of validation routines that return true if the thing they validate is okay and false otherwise, then I can easily combine them into a form validator that ends up looking like this:<BR><BR>function validate(theForm) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;return ( true<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&amp;&amp; validateTextField(theForm.whatever)<BR>&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&amp; validateDateField(theForm.somedate)<BR>&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&amp; validateTextField(theForm.someothertext)<BR>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;) }<BR><BR>Presumably routines such as validateTextField will pop up an alert with a nasty message before they fail. And then, because they return false, the entire "formValidate" function returns false and the page isn&#039t submitted.<BR><BR>By building the JS code in a string, at the same time we build the actual form, it is then easy to drop that final string in place later in the page.<BR><BR>Whaddya think?<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