Simple js validation not firing.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #31
    Originally posted by Death Slaught
    Your script is loading fine. Add this and you'll see that it works.

    [HTML]<input type="submit" />[/HTML]
    See post #3, line 149 ...

    Comment

    • Death Slaught
      Top Contributor
      • Aug 2007
      • 1137

      #32
      Originally posted by acoder
      See post #3, line 149 ...
      Oh sorry. Then sense his script is loading fine doesn't that meen that all he needs to do is enable the user to submit it. Because it works fine for me except I can't type anything in do to the readonly.

      Thanks,
      {\_/}
      (' . ')
      (")[DEATH](")
      (")(")

      Comment

      • ajos
        Contributor
        • Aug 2007
        • 283

        #33
        Originally posted by acoder
        I don't like to see a problem unsolved, but if you're happy, we'll leave it there :)
        I just forgot that a developer should never have a "i quit" attitude...Than ks for reminding me that...Ok now back to that problem...I just placed the js file to my jsp directory and when i checked my firefox error console i got an error---everything is not defined....What does this mean?
        here is once again my js file--->
        [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 += "\nFrom Date"
        }
        if(isdate2(form )==false)
        {
        text += "\nTo Date"
        }
        alert(text)
        }

        function isdate(form)
        {
        if(form.fromDat e.value =="")
        {
        return false
        }
        else
        {
        return true
        }
        }
        function isdate2(form)
        {
        if(form.toDate. value =="")
        {
        return false
        }
        else
        {
        return true
        }

        }
        [/CODE]

        and my jsp page(small portions) is like--->
        [HTML]<script type="text/javascript" src="expen2.js" ></script>[/HTML]

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

        [HTML]<input type="text" name="fromDate" maxlength="8" size="8" value="">[/HTML]

        [HTML]<input type="text" name="toDate" maxlength="8" size="8" value="" readonly="reado nly">[/HTML]

        [HTML]<input type="submit" name="thesubmit " value="Submit">[/HTML]

        Once again thanks for being patient and helpful. :)
        regards,
        ajos

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #34
          Originally posted by ajos
          I just forgot that a developer should never have a "i quit" attitude...Than ks for reminding me that...
          Lol, good attitude!
          Originally posted by ajos
          Ok now back to that problem...I just placed the js file to my jsp directory and when i checked my firefox error console i got an error---everything is not defined....What does this mean?
          The only thing I can think of is that it can't find everything() which means that the file hasn't been found. Is the file called expen2.js?

          Comment

          • ajos
            Contributor
            • Aug 2007
            • 283

            #35
            Originally posted by acoder
            Lol, good attitude!
            The only thing I can think of is that it can't find everything() which means that the file hasn't been found. Is the file called expen2.js?
            yup the file is called expen2.js....It s strange that the file cannot be found, coz ive done similar to some other pages and it works fine.

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #36
              Originally posted by ajos
              yup the file is called expen2.js....It s strange that the file cannot be found, coz ive done similar to some other pages and it works fine.
              It must be something small that no-one's noticed so far. Can you link to a test page? If not, can you produce a minimised client-side version (no JSP, just HTML/JS) that demonstrates the same problem.

              Comment

              • ajos
                Contributor
                • Aug 2007
                • 283

                #37
                Originally posted by acoder
                It must be something small that no-one's noticed so far. Can you link to a test page? If not, can you produce a minimised client-side version (no JSP, just HTML/JS) that demonstrates the same problem.
                What ive done is, got the html generated from the view source of the jsp page

                and tested with the js file with the html generated.

                when i change my view source generated html to this-->

                [HTML]<input type="button" name="thesubmit " value="Submit" onClick="everyt hing(this.form) ">[/HTML]
                It works fine but not on my jsp. i.e it works with plain html page and not with my jsp page. Strange.

                Comment

                • acoder
                  Recognized Expert MVP
                  • Nov 2006
                  • 16032

                  #38
                  Originally posted by ajos
                  It works fine but not on my jsp. i.e it works with plain html page and not with my jsp page. Strange.
                  Look at the generated source for your JSP. See if it's any different from the HTML page.

                  Comment

                  • ajos
                    Contributor
                    • Aug 2007
                    • 283

                    #39
                    Originally posted by acoder
                    Look at the generated source for your JSP. See if it's any different from the HTML page.
                    I had some struts-html tags in my jsp page, changing them to pure html tags also didnt help :(. But when i connect this script to any other page it runs fine. I'm beginning to run out of ideas here.

                    Comment

                    • acoder
                      Recognized Expert MVP
                      • Nov 2006
                      • 16032

                      #40
                      Is this code online? If so, post the link. If not, post the JSP page's HTML (view source in the browser), not a HTML page.

                      Comment

                      • ajos
                        Contributor
                        • Aug 2007
                        • 283

                        #41
                        Originally posted by acoder
                        Is this code online? If so, post the link. If not, post the JSP page's HTML (view source in the browser), not a HTML page.
                        Ok now ive managed to run the validation by changing the js code and doing some modification in my jsp page..But for some reason the page is not getting submitted after validation.
                        [CODE=javascript]
                        function everything(form ) {
                        isfromDate(form )
                        allblanks(form)
                        }

                        function allblanks(form)
                        {
                        if(isfromDate(f orm))
                        {
                        form.submit()
                        }
                        if(isfromDate(f orm) == false)
                        {
                        compose(form)
                        }
                        }

                        function compose(form) {
                        var text = "You forgot to fill in correctly:"
                        if(isfromDate(f orm) == false) {
                        text += "\nDATE"
                        }
                        alert(text)
                        }

                        function isfromDate(form )
                        {
                        if(form.fromDat e.value == "") {
                        return false
                        }
                        else {
                        return true
                        }
                        }


                        [/CODE]
                        my revised html button is

                        [HTML] <input type="button" name="thesubmit " value="Submit" onClick="everyt hing(this.form) "> &nbsp; [/HTML] .
                        Last hurdle i suppose ;). Thanks for being patient with me as ive found out how nasty a beast is javascript to debug.

                        Comment

                        • ajos
                          Contributor
                          • Aug 2007
                          • 283

                          #42
                          Hey acoder ive successfully run the page..one of the problem turned out that my compiler wasnt too happy with my decision to name my jsp page and js file as one, have you heard of it before??. Thank you for the support and encouragement, if it wasnt for you i wouldnt had learnt this. Thanks buddy:).

                          Comment

                          • acoder
                            Recognized Expert MVP
                            • Nov 2006
                            • 16032

                            #43
                            Originally posted by ajos
                            Thanks for being patient with me as ive found out how nasty a beast is javascript to debug.
                            Not so difficult with Firebug.

                            Comment

                            • acoder
                              Recognized Expert MVP
                              • Nov 2006
                              • 16032

                              #44
                              Originally posted by ajos
                              Hey acoder ive successfully run the page..one of the problem turned out that my compiler wasnt too happy with my decision to name my jsp page and js file as one, have you heard of it before??. Thank you for the support and encouragement, if it wasnt for you i wouldnt had learnt this. Thanks buddy:).
                              I didn't know that. You're talking about the Java/JSP compiler, right? Anyway, a simple solution in the end. Glad to hear that it's working now.

                              Comment

                              Working...