Simple js validation not firing.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ajos
    Contributor
    • Aug 2007
    • 283

    Simple js validation not firing.

    Hi all,
    I have a piece of script which for some reasons is not firing up, herez the script,
    [CODE=javascript]
    function everything(form )
    {
    var errors=0;
    if(!isdate(form ))
    errors++;
    if(!isdate2(for m))
    errors++;
    if(errors==0)
    return true;
    else
    {
    compose(form);
    return false;
    }
    }

    function compose(form)
    {
    var text= "You forgot to fill in correctly:"
    if(isdate(form) ==false)
    {
    text += "\nDate"
    }
    alert(text)
    }

    function isdate(form)
    {
    if(expenqryForm .from_Date.valu e == "")
    {
    return false
    }
    else
    {
    return true
    }
    }
    function isdate2(form)
    {
    if(expenqryForm .to_Date.value == "")
    {
    return false
    }
    else
    {
    return true
    }

    }

    [/CODE]
    And here is my view source page--->
    [HTML]<SCRIPT LANGUAGE="JavaS cript" SRC="ipubscript 1.js"></SCRIPT>[/HTML]
    [HTML]<input type="text" name="from_Date " maxlength="8" size="8" value="" readonly="reado nly">[/HTML]
    [HTML] <input type="text" name="to_Date" maxlength="8" size="8" value="" readonly="reado nly">[/HTML]
    [HTML]<form name="expenqryF orm" method="post" action="/publicity/ExpenQryAction. do" onsubmit="retur n everything(this );">[/HTML]

    Why is this script failing?.
    Help appreciated :)
    regards,
    ajos
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    In the isDate functions, replace expenqryForm with form (the variable passed as an argument to the function).

    Comment

    • ajos
      Contributor
      • Aug 2007
      • 283

      #3
      Originally posted by acoder
      In the isDate functions, replace expenqryForm with form (the variable passed as an argument to the function).
      Hi acoder. I tried that but that didnt work though, what may be the problem...
      this is my complete jsp page....
      [HTML]
      <html>
      <head>
      <title>PAYMEN T DETAIL QUERY</title>
      <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
      <SCRIPT LANGUAGE="JavaS cript" SRC="ipubscript 1.js"></SCRIPT>
      <script type="text/javascript" SRC="calendar1. js"></script>
      <script type="text/javascript">
      function forward(control )
      {
      var branch = control.value;
      location.href="/publicity/ExpenQryAction. do?branch=" +branch;
      }
      function messageValue()
      {
      var messageIndex = document.expenq ryForm.branch.s electedIndex;
      var selectedValue = document.expenq ryForm.branch.o ptions[messageIndex].value;
      document.expenq ryForm.branch.v alue = selectedValue;
      document.expenq ryForm.publicit y_Code.selected Index;
      document.expenq ryForm.submit() ;
      }
      function messValue()
      {
      var messIndex=docum ent.expenqryFor m.publicity_Cod e.selectedIndex ;
      var selValue = document.expenq ryForm.publicit y_Code.options[messageIndex].value;
      document.expenq ryForm.publicit y_Code.value=se lectedValue;
      document.expenq ryForm.submit() ;
      }
      </script>
      </head>
      <body topmargin="0" leftmargin="0" bgproperties="f ixed">

      <div align="left">
      <form name="expenqryF orm" method="post" action="/publicity/ExpenQryAction. do" onsubmit="retur n everything(this );">

      <table border="0" width="100%">
      <tr>
      <td width="100%" bgcolor="#DFDFF F" background="ima ges/niceblue.gif">< font face="Tahoma"
      color="#000000" ><strong>P a y m e n t&nbsp;&nbsp; Q u e r y</strong></font></td>
      </tr>
      </table>
      <div align="left">

      <table border="0" cellpadding="0" cellspacing="0" width="100%" height="109">
      <tr>
      <td width="35%" height="42"></td>
      <td width="65%" height="42"></td>
      </tr>
      <tr>
      <td width="35%" height="25"><st rong><small><fo nt face="Verdana"> Requisition Code</font></small></strong></td>
      <td width="65%" height="25">
      <input type="text" name="req_Code" maxlength="10" size="8" value="">

      </td>
      </tr>
      <tr>
      <td width="35%" height="21"><sm all><strong><fo nt face="Verdana"> Party Name </font></strong></small></td>
      <td width="65%" height="21">
      <input type="text" name="party_Nam e" maxlength="255" size="8" value="">

      </td>
      </tr>
      <tr>
      <td width="35%" height="21"><st rong><small><fo nt face="Verdana"> From Bill Date </font></small></strong></td>
      <td width="65%" height="21"><st rong><small><fo nt face="Verdana">
      <input type="text" name="from_Date " maxlength="8" size="8" value="" readonly="reado nly">
      <a href="javascrip t:cal1.popup(); "><img src="images/cal.gif" width="16" height="16" border="0" alt="Click Here to Pick up the date"></a><br>

      </font></small></strong></td>
      </tr>
      <tr>
      <td width="35%" height="21"><sm all><strong><fo nt face="Verdana"> To Bill Date </font></strong></small></td>
      <td width="65%" height="21"><sm all><strong><fo nt face="Verdana">
      <input type="text" name="to_Date" maxlength="8" size="8" value="" readonly="reado nly">
      <a href="javascrip t:cal2.popup(); "><img src="images/cal.gif" width="16" height="16" border="0" alt="Click Here to Pick up the date"></a><br>
      </font></strong></small></td>
      </tr>
      <tr>
      <td width="35%" height="21"><sm all><strong><fo nt face="Verdana"> Less than Amount </font></strong></small></td>
      <td width="65%" height="21"><sm all><strong><fo nt face="Verdana">
      <input type="text" name="less_Amt" maxlength="10" size="8" value="">

      </font></strong></small></td>
      </tr>
      <tr>
      <td width="35%" height="21"><st rong><small><fo nt face="Verdana"> Greater than Amount</font></small></strong></td>
      <td width="65%" height="21"><sm all><strong><fo nt face="Verdana">
      <input type="text" name="greater_A mt" maxlength="10" size="8" value="">

      </font></strong></small></td>
      </tr>


      <tr>
      <td width="35%" height="21"><sm all><strong><fo nt face="Verdana"> Branch</font></strong></small></td>
      <td width="65%" height="21"><st rong><font face="Verdana"> <small></small></font></strong>
      <select name="branch" size="1" onChange="messa geValue()">
      <option value=""><optio n>
      <option value="Bombay" selected>Bombay </option>
      <option value="Delhi" >Delhi</option>
      <option value="Ahmedaba d" >Ahmedabad</option>
      <option value="Madras" >Madras</option>
      <option value="Bangalor e" >Bangalore</option>
      <option value="Calcutta " >Calcutta</option>
      <option value="Hyderaba d" >Hyderabad</option>
      <option value="Pune" >Pune</option>
      <option value="Lucknow" >Lucknow</option>
      <option value="Jaipur" >Jaipur</option>
      <option value="Patna" >Patna</option>
      <option value="Cochin" >Cochin</option>
      <option value="Chandiga rh" >Chandigarh</option>
      <option value="Bhopal" >Bhopal</option>
      <option value="x">-------------------------------<option>
      </select>
      <strong><font face="Verdana"> <small></small></font></strong></td>
      </tr>

      <tr>
      <td width="35%" height="21"><sm all><strong><fo nt face="Verdana"> Publicity Head</font></strong></small></td>
      <td width="65%" height="21"><st rong><font face="Verdana"> <small></small></font></strong>
      <select name="publicity _Code" size="1">

      <option value="">(selec t all)</option>

      <option value="41604" selected >41604</option>

      </select>

      <strong><font face="Verdana"> <small></small></font></strong></td>
      </tr>

      <tr>
      <td width="35%" height="21"><sm all><strong><fo nt face="Verdana"> Expenditure Type</font></strong></small></td>
      <td width="65%" height="21"><st rong><font face="Verdana"> <small></small></font></strong>
      <select name="expenditu re_Code" size="1"><optio n value=""></option>

      <option value="41604101 ">Cost Of Items</option></select>


      <strong><font face="Verdana"> <small></small></font></strong></td>
      </tr>
      </table>
      </div><div align="left">

      <table width="70%">
      <tr>
      <td width="50%"><p align="left">


      <input type="submit" name="thesubmit " value="Submit">
      <input type="reset" name="reset" value="Reset">

      </td>
      <td width="50%"><p align="center"> </td>
      </tr>
      </table>
      </div>

      <dd align="center"> <br>
      </dd>
      </form>
      <script type="text/javascript">
      var cal1 = new calendar1(docum ent.forms['expenqryForm'].elements['from_Date']);
      </script>
      <script type="text/javascript">
      var cal2 = new calendar1(docum ent.forms['expenqryForm'].elements['to_Date']);
      </script>
      </div>
      </body>
      </html>
      [/HTML]

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        What do the isDate functions look like now? Do you get any errors?

        Comment

        • ajos
          Contributor
          • Aug 2007
          • 283

          #5
          Originally posted by acoder
          What do the isDate functions look like now? Do you get any errors?
          [CODE=javascript]
          function isdate(form)
          {
          if(form.fromDat e.value =="")
          {
          return false
          }
          else
          {
          return true
          }
          }
          [/CODE]
          This is my isdate function. The problem gets solved by adding the script directly in my jsp page in the <head> but when i try to use the external file it gives me Object expected error, but it still gives me Object expected error if i add the script in the jsp page, but it works.

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            fromDate and toDate have underscores, i.e. from_Date and to_Date.

            Comment

            • ajos
              Contributor
              • Aug 2007
              • 283

              #7
              Originally posted by acoder
              fromDate and toDate have underscores, i.e. from_Date and to_Date.
              Thats no problem coz i just changed my naming convention to something better...so from_Date becomes fromDate....The problem exists for a js file used externally.

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                Originally posted by ajos
                The problem gets solved by adding the script directly in my jsp page in the <head> but when i try to use the external file it gives me Object expected error, but it still gives me Object expected error if i add the script in the jsp page, but it works.
                Which line does the error occur on?

                Comment

                • ajos
                  Contributor
                  • Aug 2007
                  • 283

                  #9
                  Originally posted by acoder
                  Which line does the error occur on?
                  The lines are 43,47,59,55,51 shown in IE browser. Im sorry im not sure on how to determine which line it is...is there a way?
                  Last edited by ajos; Feb 11 '08, 11:08 AM. Reason: more errors

                  Comment

                  • acoder
                    Recognized Expert MVP
                    • Nov 2006
                    • 16032

                    #10
                    Check the error console in, say, Firefox.

                    Comment

                    • ajos
                      Contributor
                      • Aug 2007
                      • 283

                      #11
                      Originally posted by acoder
                      Check the error console in, say, Firefox.
                      Ok i found out in firefox, that the lines that i mentioned were not related to the js that i am working with.....but nothing related to why 'this' js script is not working? working fine when i include the script between <script> in <head>, but not for src property....i cant understand why?
                      Any answers :) ?

                      Comment

                      • acoder
                        Recognized Expert MVP
                        • Nov 2006
                        • 16032

                        #12
                        Originally posted by ajos
                        Ok i found out in firefox, that the lines that i mentioned were not related to the js that i am working with...
                        Could it be the calendar script?
                        Are the whole contents of the script that you're including, just the validation code posted earlier?

                        Comment

                        • ajos
                          Contributor
                          • Aug 2007
                          • 283

                          #13
                          Originally posted by acoder
                          Could it be the calendar script?
                          Are the whole contents of the script that you're including, just the validation code posted earlier?
                          It could'nt be the calendar script. The script that i posted in my first post is all the script that im using...ive done this before, but for some reason this is not working ...im amused by this.
                          I would also like to add that when i place my script in a external file(.js) and call it the error i get i "everything is not defined" !!. How can this be possible?

                          Comment

                          • acoder
                            Recognized Expert MVP
                            • Nov 2006
                            • 16032

                            #14
                            Originally posted by ajos
                            I would also like to add that when i place my script in a external file(.js) and call it the error i get i "everything is not defined" !!. How can this be possible?
                            I know this might seem like a silly question, but is the external file called "ipubscript1.js " and is it in the same directory as the main file?

                            Comment

                            • ajos
                              Contributor
                              • Aug 2007
                              • 283

                              #15
                              Originally posted by acoder
                              I know this might seem like a silly question, but is the external file called "ipubscript1.js " and is it in the same directory as the main file?
                              No a valid question:). Yup, its in the same directory in which my jsp page is situated in the WEB-INF folder. I got a question, does having multiple js files/scripts in the jsp pages in any way has an effect on the other present script?.

                              Comment

                              Working...