Results 1 to 6 of 6

Thread: I can not find the js function in the code ?

  1. #1
    Join Date
    Oct 2004
    Posts
    425
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default I can not find the js function in the code ?

    To below page there is a form with onsubmit return validation function well although validation works I can not find the js function in the code ?

    http://dimitriavilla.com/book_here.htm

    I want to add the validation function below to form so bookInDate<bookOutDate , how to include the two functions (& return keyword) to one onsubmit event handler ?

    Code:
    <script type="text/javascript">
    function submitForm() {
     if (document.book.Email.value == "") {
        window.alert("You must enter your email address to submit form!");
     return false;
     }
     var startDate = new Date(document.book.DATEFROM_YEAR.value,document.book.DATEFROM_MONTH.value-1,document.book.DATEFROM_DAY.value);   //  var startDate = new Date(document.forms[0].year.value,document.forms[0].month.value,document.forms[0].day.value);
     var endDate = new Date(document.book.DATETO_YEAR.value,document.book.DATETO_MONTH.value-1,document.book.DATETO_DAY.value);   //  var endDate = new Date(document.forms[0].toyear.value,document.forms[0].tomonth.value,document.forms[0].today.value);
    
     if (startDate.getTime() > endDate.getTime()) {   //  startDate.valueof() > endDate.valueof()
        window.alert("You must enter Start Date prior End Date to submit form!");
     return false;
     }
     else 
        return true;
    }  // end function   p261 gosselin book
    </script>

  2. #2
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Based on the <form> element that you are using onsubmit event handler is a function whose name is 'FrontPage_Form1_Validator', which is inside the table that you used for the form fields placement.

    You can add your own functions into the above mentioned function and it usually expects to reuturn a true value if the checking is success otherwise false, which will eventually block the form submission.

  3. #3
    Join Date
    Oct 2004
    Posts
    425
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default

    for two functions to onsubmit below is correct ?

    onsubmit="return f1(); return f2();"

  4. #4
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    It is better if you combine these two function into one rather than calling them as two different methods.

  5. #5
    Join Date
    Oct 2004
    Posts
    425
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default

    I can not view this code in frontpage2002 code view although when i view page[] and source i view it successfully ? wheni copy code and paste to fp2002 direct editting from web when save disappears the code and saved ?
    Code:
                <!--webbot BOT="GeneratedScript" PREVIEW=" " startspan --><script Language="JavaScript" Type="text/javascript"><!--
    function FrontPage_Form1_Validator(theForm)
    {
    
      if (theForm.Country.selectedIndex < 0)
      {
        alert("Please select one of the \"Country\" options.");
        theForm.Country.focus();
        return (false);
      }
    
      if (theForm.Country.selectedIndex == 0)
      {
        alert("The first \"Country\" option is not a valid selection.  Please choose one of the other options.");
        theForm.Country.focus();
        return (false);
      }
    
      if (theForm.LastName.value == "")
      {
        alert("Please enter a value for the \"LastName\" field.");
        theForm.LastName.focus();
        return (false);
      }
    
      if (theForm.FirstName.value == "")
      {
        alert("Please enter a value for the \"FirstName\" field.");
        theForm.FirstName.focus();
        return (false);
      }
    
      if (theForm.HomePhone.value == "")
      {
        alert("Please enter a value for the \"HomePhone\" field.");
        theForm.HomePhone.focus();
        return (false);
      }
    
      if (theForm.Email.value == "")
      {
        alert("Please enter a value for the \"Email\" field.");
        theForm.Email.focus();
        return (false);
      }
    
      if (theForm.Email2.value == "")
      {
        alert("Please enter a value for the \"Email2\" field.");
        theForm.Email2.focus();
        return (false);
      }
    
      if (theForm.Adults.value == "")
      {
        alert("Please enter a value for the \"Adults\" field.");
        theForm.Adults.focus();
        return (false);
      }
    
      if (theForm.Children.value == "")
      {
        alert("Please enter a value for the \"Children\" field.");
        theForm.Children.focus();
        return (false);
      }
      return (true);
    }
    //--></script><!--webbot BOT="GeneratedScript" endspan -->

  6. #6
    Join Date
    Oct 2004
    Posts
    425
    Thanks
    4
    Thanked 1 Time in 1 Post

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
  •