SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Addict michael - ohio's Avatar
    Join Date
    Dec 2004
    Location
    ohio
    Posts
    257
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    quick question about checking a field for empty (if/else - redirect)

    I think this is a really quick question - and would appreciate any help...


    I have the following simple form vaidation script on a [classic] ASP page:


    Code VB:
    <script>
    	function validateForm(frm)
    		{
    		if(frm.subject.value=="")
    		{
    		alert('You must provide a subject.');
    		frm.subject.focus;
    		return false;
    		}
    		if(frm.message.value=="")
    		{
    		alert('You must provide a message.');
    		frm.message.focus;
    		return false;
    		}
    	frm.submit();
    	}
    </script>

    ---------------------------------------
    I want to add one more validation
    at the beginning of the script,
    just to slow down spam bots:


    For the following input field:

    Code HTML4Strict:
    <input type="text" name="foo" style="display: none;">

    The validation should:

    if [foo] equals "" contunue to the rest of the validation
    else
    if [foo] doesn't = "" redirect to [http://foo.com/page.asp]



    Getting the script syntax right is driving me nuts -
    can you help?

    Thanks,

    - Michael
    (obviously not a coder)

    http://www.sitepoint.com/easy-spam-prevention-using-hidden-form-fields/

  2. #2
    SitePoint Zealot moretea's Avatar
    Join Date
    Jun 2004
    Location
    Texas, USA
    Posts
    118
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Looks more like JScript to me... I think you're looking for something like this (no guarantees though, I haven't tested it):

    Code:
    <script>
    	function validateForm(frm)
    		{
    		if(frm.subject.value=="")
    		{
    		alert('You must provide a subject.');
    		frm.subject.focus;
    		return false;
    		}
    		if(frm.message.value=="")
    		{
    		alert('You must provide a message.');
    		frm.message.focus;
    		return false;
    		}
                    if (frm.foo.value != "" || frm.foo.length != 0) {
                    response.redirect('foo.asp');
                    }
    	frm.submit();
    	}
    </script>

  3. #3
    SitePoint Addict michael - ohio's Avatar
    Join Date
    Dec 2004
    Location
    ohio
    Posts
    257
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I couldn't get it to work exactly the way you described:
    if (frm.foo.value != "" || frm.foo.length != 0)
    The form wouldn't submit (or maybe just didn't validate?)

    But when I eliminated the || check for !=0 like this:
    if (frm.foo.value != "")
    it appears to work. Thank you!

    (any idea on how to add back in the check for !=0 ??)

    Again - Thanks for your help.

  4. #4
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Can you show us more of the page please? Specifically your code In Context with the rest of the page, including your HTML form? (Delete or mask anything sensitive or personal).

    (To me it looks like you're trying to mix Javascript and ASP).
    Ian Anderson
    www.siteguru.co.uk


Tags for this Thread

Bookmarks

Posting Permissions

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