Prompt to submit

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Matthew

    #1

    Prompt to submit

    I have a form that the user can edit data in. However, there are a couple
    of links on the page. The user can edit the data and click on a link, not
    submitting the form.

    Is there some code out there that will check to see if they changed the
    form, and prompt them to submit it if they try to exit the page any other
    way?

    Perfect example:

    Using IE, scan for updates, then click "personaliz e windows update". Change
    something on that list, then try to navigate away.

    Matthew



  • Juliette

    #2
    Re: Prompt to submit

    Matthew wrote:[color=blue]
    >
    > I have a form that the user can edit data in. However, there are a couple
    > of links on the page. The user can edit the data and click on a link, not
    > submitting the form.
    >
    > Is there some code out there that will check to see if they changed the
    > form, and prompt them to submit it if they try to exit the page any other
    > way?
    >
    > Perfect example:
    > www.windowsupdate.com
    > Using IE, scan for updates, then click "personaliz e windows update". Change
    > something on that list, then try to navigate away.
    >
    > Matthew[/color]

    Matthew,

    You can use the onUnload event in combination with some form checks
    which check the current value of the form fields against the default
    values.
    Not secure, not foolproof (you can easily turn off javascript), but it
    will allow you to do what you ask.

    Gr, J.

    Comment

    • Matthew

      #3
      Re: Prompt to submit

      Thanks.

      This is just for my customers convenience; no "security" necessary.

      Matthew



      Comment

      • Matthew

        #4
        Re: Prompt to submit

        Below is the code I wrote.

        It seems to work properly. As I am a bit new to JavaScript, can somebody
        take a look at the logic for inefficiencies?

        I don't know a better way to do "function nocheck".

        Also, is there a quick, easy way to submit the form "cart", then continue to
        where they wanted to go originally?

        Thanks for the help.

        Matthew

        Code:

        <HEAD>
        <script type="text/JavaScript">
        <!--

        function nocheck() {
        changeform = nothing
        }

        function nothing(){
        }

        function changeform() {
        if (checkform())
        {
        return true
        } else {
        var confirmed = confirm("You have changed the quantity of an item.\nClick
        OK to save your changes.");
        if (confirmed == true) {
        document.cart.s ubmit();
        return false
        } else {
        return true
        }
        return false
        }
        }

        function checkform() {
        if (document.cart. qty01.value != 8)
        {
        return false
        }
        if (document.cart. qty02.value != 7)
        {
        return false
        }
        if (document.cart. qty03.value != 6)
        {
        return false
        }
        if (document.cart. qty04.value != 4)
        {
        return false
        }
        return true
        }
        //-->
        </script>
        </HEAD>
        <BODY onUnload="chang eform();">
        <FORM method="post" name="cart" action="test.ht m" onSubmit="noche ck();">

        some code

        </FORM>

        some links

        </BODY>



        Comment

        • Dr John Stockton

          #5
          Re: Prompt to submit

          JRS: In article <x9XTb.3244$cx3 .1717@fe01.usen etserver.com>, seen in
          news:comp.lang. javascript, Matthew <turn.deletethi s@alltel.net> posted
          at Tue, 3 Feb 2004 19:37:46 :-[color=blue]
          >
          >function changeform() {
          >if (checkform())
          > {
          > return true
          > } else {
          > var confirmed = confirm("You have changed the quantity of an item.\nClick
          >OK to save your changes.");
          > if (confirmed == true) {
          > document.cart.s ubmit();
          > return false
          > } else {
          > return true
          > }
          > return false
          > }
          >}[/color]



          function changeform() {
          if (checkform()) return true // else not needed after return
          var confirmed = confirm("You have changed the quantity of an item." +
          "\nClick OK to save your changes.");
          if (confirmed) document.cart.s ubmit() // ==true is normally pointless
          return !confirmed }

          I split the string in order to for News convention of margin 72; code
          should NEVER be wrapped by a system that does not understand it.

          The return statement is an EXIT statement; not like Result in Delphi,
          which is a variable that can be accessed repeatedly.

          While else is perfectly legal, nested else becomes hard to read. Some
          teach that functions should only be exited at their ends; my view is
          that their exits should be obvious - so the early return could be
          commented // EARLY RETURN.

          --
          © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
          <URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
          <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
          <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

          Comment

          • Matthew

            #6
            Re: Prompt to submit

            Thanks for looking at the code.

            It looks much cleaner.

            Matthew



            Comment

            • Dr John Stockton

              #7
              Re: Prompt to submit

              JRS: In article <x9XTb.3244$cx3 .1717@fe01.usen etserver.com>, seen in
              news:comp.lang. javascript, Matthew <turn.deletethi s@alltel.net> posted
              at Tue, 3 Feb 2004 19:37:46 :-
              [color=blue]
              >function checkform() {
              > if (document.cart. qty01.value != 8)
              > {
              > return false
              > }
              > if (document.cart. qty02.value != 7)
              > {
              > return false
              > }
              > if (document.cart. qty03.value != 6)
              > {
              > return false
              > }
              > if (document.cart. qty04.value != 4)
              > {
              > return false
              > }
              >return true
              >}[/color]


              The following should be equivalent; but it seems a strange need :

              function checkform() { return (
              document.cart.q ty01.value == 8 &&
              document.cart.q ty02.value == 7 &&
              document.cart.q ty03.value == 6 &&
              document.cart.q ty04.value == 4 ) }

              function checkform() { with (document.cart) return (
              qty01.value == 8 && qty02.value == 7 &&
              qty03.value == 6 && qty04.value == 4 ) }




              To turn off checking by function X, use global G

              function X() {
              if (G) return true // or false
              <series-of-tests> }

              function X() {
              return G || <series-of-tests> }

              function X() {
              return G && <series-of-tests> }

              The first and second return true if G is true; the third returns false
              if G is false; in each case, without further tests. I think.

              --
              © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
              <URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
              <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
              <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

              Comment

              Working...