server side forms validation (JScript)

Results 1 to 2 of 2

Thread: server side forms validation (JScript)

  1. #1
    David D. Guest

    Default server side forms validation (JScript)

    I thought I could do this to see if my form was filled out:<BR><BR>if ( Request.Form("aFormField") == null ) {<BR> // (re)display the form<BR>}<BR>else {<BR> // process the form and proceed to next page if no errors...<BR>}<BR><BR>however the if statement does not evaluate true if the form is<BR>empty ( Request.Form("aFormField") is "undefined").<BR>JScript (and JavaScript) say that they match undefined to null<BR><BR>what simple advice am I missing?<BR><BR>-- thanks!

  2. #2
    David D. Guest

    Default RE: server side forms validation * Found It*, but

    using the typeof operator I found that <BR>Request.Form("aFormField") was returning: object<BR>Then I found the following in MSDN Library: <BR><BR> (!obvious && prettyFlaky) if you ask me...<BR>----------------------------------------------------------------<BR>Processing User Input<BR>This is preliminary documentation for IIS 5.0 and is subject to change. <BR><BR>Important If your are using JScript for server-side validation, be sure to place a pair of empty parentheses following the Request collection item (either QueryString or Form) when you are assigning the collection to a local variable. Without parenthesis, the collection returns an object, rather than a string. The following script illustrates the correct way to assign variables with JScript:<BR><BR>&#060;%<BR> var Name = Request.Form("Name")();<BR> var Password = Request.Form("Password")();<BR><BR> if(Name &#062; "")<BR> {<BR> if(Name == Password)<BR> Response.Write("Your name and password are the same.")<BR> else<BR> Response.Write("Your name and password are different.");<BR> }<BR>%&#062;<BR><BR>VBScript exhibits the same behavior if the collection contains multiple values that are comma-separated or indexable. This means that for both VBScript and JScript, in addition to placing a pair of empty parentheses following the Request collection item, you will need to specify the index of the desired value. For example, the following line of JScript returns only the first of multiple values for a form element:<BR><BR>var Name = Request.Form("Name")(1);<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