Results 1 to 4 of 4

Thread: JS, ASP: Best way to validate? easy [resolved]

  1. #1

    Thread Starter
    Fanatic Member invitro's Avatar
    Join Date
    Jan 2000
    Location
    Outside your window
    Posts
    547

    JS, ASP: Best way to validate? easy [resolved]

    Ok here is the plan:

    PageA.asp has a form. On that form I have

    txtUser
    txtPassword
    cmdSubmit

    After hitting submit, user gets redirected to PageB.asp where the result (user data) is stored in a database.

    Now, what is the best way to validate that the user has filled out all the fields.

    Do I do it in PageB.asp or PageA.asp
    I was thinking of embeding a simple JS function into

    Code:
    <FORM ACTION="JS FUNCTION HERE">
    </FORM>
    Is that possible? Is that a good way of doing it, or does it have something to do with the actual Submit button.

    I'm also pretty sure I could check the values on PageB.asp, to see if they are blank and display an error... would that work?

    Thanks a lot,
    InVitro
    Last edited by invitro; May 23rd, 2003 at 03:21 PM.
    ok, so... windows takes 1 minute to search for a file on my PC yet google.com takes 1 second to search the entire internet?

  2. #2
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724
    This is what we use:

    Code:
    <script language="JavaScript">
        function validate(obj) {
            if (obj.Field.value == "") {
                alert("Some message goes here");
                obj.focus();
                return false;
            }
    
            return true;
        };
    </script>
    
    <form name="blah" method="post" action="somepage.asp" onsubmit="return validate(this);">
        <input type="text" name="Field">
    </form>

  3. #3
    Frenzied Member DeadEyes's Avatar
    Join Date
    Jul 2002
    Posts
    1,196
    Using Javascript like axion_sa provided is a good way to do a quick check and give the user timely feedback without having to wait for the form to be sent to the server and back.
    But it is good practice to do the checks again on the server side like checks for single quotes (used to always catch me out with peoples names)

  4. #4

    Thread Starter
    Fanatic Member invitro's Avatar
    Join Date
    Jan 2000
    Location
    Outside your window
    Posts
    547
    Perfect, thanks a lot!
    ok, so... windows takes 1 minute to search for a file on my PC yet google.com takes 1 second to search the entire internet?

Posting Permissions

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



Click Here to Expand Forum to Full Width