Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2004

    Question Unanswered: Javascript Validation In Asp Forms


    i have one problem with asp and javascripting..again....i have a form designed in which user has to enter values....out of these some values have to be entered compulsarily...and there is no guarantee that he will come to that text box..bcoz rest are selections which he may prefer doing using on blur event does not work...and then if he gets on to submit button then even if the user has not entered necessary values the page moves on to the next do i have any method using which i can mandate the user to enter the values as well as i also take care that the page does not get submitted ????????

    also another problem is that everytime method opens up a new window.....can u please tell me how to do this where it opens in the same window everytime.....

    please help me out.......thanx in advance.....


  2. #2
    Join Date
    Jul 2003
    You can do the validation two ways. Through JavaScript or through ASP. The problem with JavaScript is that someone can turn it off. ASP they cannot. Through JavaScript, you put an onSubmit() handler in the <form> tag. When your form is submit, onSubmit is caught and your code executed. Returning a true or false to the onSubmit will either stop the submit, or allow it to continue:

    <form name="myform" action="mypage.asp" method="post" onSubmit="return checkForm();">

    Now you need to create a function to check your values:

    <script language="javascript">
    function checkForm(){
        // Check the form values here to make sure they meet your criteria
        // If the fields pass do:
        return true;
        // If the fields fail do:
        return false;
    This will return true or false back to the first return statement which returns true or false back to the onSubmit, telling the form to go or not.

    Now, you can also do this in ASP, and just check the values after the submit. If the values fail, you redisplay the form with the values they typed in and mark the field that failed the test.

    As for popup windows, it's the window name attribute of the function.
    Code:'mypage1.asp', 'myWindow', '');'mypage2.asp', 'myWindow', '');'mypage3.asp', 'myWindow', '');
    Now all three pages should load in the same window.
    That which does not kill me postpones the inevitable.

Posting Permissions

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