How could I choose between using Jscript ELSE php validation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JnrJnr
    New Member
    • Oct 2009
    • 88

    #1

    How could I choose between using Jscript ELSE php validation

    Hi all,
    how can I choose to use JavaScript (and if not available) use PHP in this example?
    I have an HTML select control that has two onchange methods. The first one calls a JavaScript validation (getValues();) and the second calls for server validation (this.form.submi t();).

    Code:
    <select id="selectID" name="selectName" onchange="[B]getValues[/B](); [B]this.form.submit[/B]()">
    <option></option>
    <option></option>
    <option></option>
    </select>
    I only want the server validation (this.form.submi t();)
    to occur if javascript is disabled. Else use JavaScript
    Any advice please?
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    don’t do that.

    always use server-side validation regardless if there was client side validation or not.

    Comment

    • Rabbit
      Recognized Expert MVP
      • Jan 2007
      • 12517

      #3
      I agree, always use server side validation. But if you want, do both, so the user can have instant feedback before submission.

      Comment

      • JnrJnr
        New Member
        • Oct 2009
        • 88

        #4
        ok, I dont think I explained it correctly. Its not really validation but rather just to make the form more interactive. Lets call it functionality.
        I already have server side functionality and javascript functionality. All I want to do is choose between the two. If the user has Jscript disabled then use serverside code to do the job else let Jscript do it quicker.
        Is there a way I could?

        Comment

        • JnrJnr
          New Member
          • Oct 2009
          • 88

          #5
          At the moment it is doing both. I only want it to do the one or the other. If it cant do Jscript then it has no choice but to do it server side.

          Comment

          • Rabbit
            Recognized Expert MVP
            • Jan 2007
            • 12517

            #6
            It would help to know what it is that you're trying to do.

            Comment

            • JnrJnr
              New Member
              • Oct 2009
              • 88

              #7
              Im making a FAQs page that when you click on the question it pops out the answer. Take a look at the code above. The onchange="getVa lues(); this.form.submi t()" is calling two methods. The first one is Jscript and the second will post the form with PHP. I want the second method to run ONLY if Jscript is not enabled.

              Comment

              • Rabbit
                Recognized Expert MVP
                • Jan 2007
                • 12517

                #8
                You'll need to set up a splash page that attempts to submit itself with javascript. If it does, you can send back a page with the javascript. If not, they will click on a link in the splash page that takes them to a page without javascript.

                If you don't want to do a splash page or have them click a link to get to a non-javascript page, you could combine them both into one page. It's just a bit more complex. It would have to attempt to submit itself using javascript with a default page of using php. But if it's able to submit itself using javascript, then you can return a page using just javascript.

                Comment

                • JnrJnr
                  New Member
                  • Oct 2009
                  • 88

                  #9
                  Ok well thanks for the replies and ideas.
                  What I did was use <noscript> tags to add a submit button to the form if there's no Jscript enabled. I guess I could make a splash page or something. (I see yahoo does that)
                  Its quite stupid or not understandable why an html onchange event does not work if Jscript is disabled even if the onchange event is just to submit the html form. Any ideas why?
                  Thanks

                  Comment

                  • Rabbit
                    Recognized Expert MVP
                    • Jan 2007
                    • 12517

                    #10
                    Because events are used to trigger scripts. Using an event to submit a page is in essence using a script to submit a page.

                    Comment

                    • Dormilich
                      Recognized Expert Expert
                      • Aug 2008
                      • 8694

                      #11
                      Because events are used to trigger scripts.
                      or even more plain, Events are a JavaScript thing (=> DOM). not part of any HTML (HTML only defines attributes not the events themselves).

                      Comment

                      • JnrJnr
                        New Member
                        • Oct 2009
                        • 88

                        #12
                        Ok all good. Thanks for the replies guys

                        Comment

                        Working...