Action From An Alert Box

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

    Action From An Alert Box

    I have a link that when clicked does something on another machine, and it
    all works fine.
    <a href=http://www.remotedomai n.com/cgi-bin/task.cgi?identi fier>Do That
    Thing</a>

    But I thought it might be a good idea to verify the user is wants to do it
    (and didn't click on the link by accident), so I added the following
    javascript:


    <script language="JavaS cript">
    function doit() {
    if(confirm('Do you really want to do that thing?'))
    { decision.value =
    'http://www.remotedomai n.com/cgi-bin/task.cgi?identi fier;' submit(); }
    }

    </script>



    <a href="javascrip t:doit()">Do That Thing</a>

    The alert box pops up fine, but I've tried a bunch of different things and I
    can't get the link to work when the user clicks on the OK button.

    Can someone please give me an idea what's wrong?



  • Charles Banas

    #2
    Re: Action From An Alert Box

    i'll try preempting the experts and see how i fare. :)

    On Wed, 27 Aug 2003 18:08:13 GMT, Slartybartfast <webmeister@hot mail.com>
    wrote:
    [color=blue]
    > I have a link that when clicked does something on another machine, and it
    > all works fine.
    > <a href=http://www.remotedomai n.com/cgi-bin/task.cgi?identi fier>Do That
    > Thing</a>
    >
    > But I thought it might be a good idea to verify the user is wants to do
    > it
    > (and didn't click on the link by accident), so I added the following
    > javascript:
    >
    >
    > <script language="JavaS cript">
    > function doit() {
    > if(confirm('Do you really want to do that thing?'))
    > { decision.value =
    > 'http://www.remotedomai n.com/cgi-bin/task.cgi?identi fier;' submit(); }
    > }
    >
    > </script>
    >
    >
    >
    > <a href="javascrip t:doit()">Do That Thing</a>
    >
    > The alert box pops up fine, but I've tried a bunch of different things
    > and I
    > can't get the link to work when the user clicks on the OK button.
    >
    > Can someone please give me an idea what's wrong?
    >[/color]
    try doing it this way:

    <a href="http://www.remotedomai n.com/cgi-bin/task.cgi?identi fier"
    onclick="confir m('Do you really want to do that thing?');">Do That
    Thing</a>

    since confirm() returns true or false, true will allow the link to continue
    and false will abort it.

    now. let's see what i did wrong. i know i missed something. :)

    --
    Charles Banas

    Comment

    • Richard Cornford

      #3
      Re: Action From An Alert Box

      "Charles Banas" <none4u@myplace .net> wrote in message
      news:opruktp9rc ccvy18@news.cab leone.net...
      <snip>[color=blue]
      ><a href="http://www.remotedomai n.com/cgi-bin/task.cgi?identi fier"
      >onclick="confi rm('Do you really want to do that thing?');">Do
      >That Thing</a>
      >
      >since confirm() returns true or false, true will allow the link to
      >continue and false will abort it.
      >
      >now. let's see what i did wrong. i know i missed something. :)[/color]

      You forgot to return a value from the onclick handler. With out a return
      value the navigation will not be cancelled:-

      onclick="return confirm('Do . . . thing?');"

      Richard.


      Comment

      • Charles Banas

        #4
        Re: Action From An Alert Box

        On 27 Aug 2003 20:55:30 +0200, Lasse Reichstein Nielsen <lrn@hotpop.com >
        wrote:
        [color=blue]
        > The experts would add a "return" in front of the call to "confirm" :)
        >
        > ... onclick="return confirm(...)"
        >[/color]
        pah. i knew it. i always forget something. :)
        [color=blue][color=green]
        >> now. let's see what i did wrong. i know i missed something. :)[/color]
        >
        > To know what it is that you do not know, is a kind of omniscience.
        > /L[/color]

        too bad i'm not God, eh.

        --
        Charles Banas

        Comment

        • Jim Dabell

          #5
          Re: Action From An Alert Box

          Slartybartfast wrote:
          [color=blue]
          > I have a link that when clicked does something on another machine,[/color]

          GET methods are supposed to be "safe". They are not meant to change state
          on a server.

          <URL:http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9. 1>
          <URL:http://www.cs.tut.fi/~jkorpela/forms/methods.html>

          Have you considered using a form with POST?

          [color=blue]
          > and it all works fine.
          > <a href=http://www.remotedomai n.com/cgi-bin/task.cgi?identi fier>Do That
          > Thing</a>[/color]

          For some value of "works fine". It's incorrect HTML and can cause problems:

          <URL:http://www.cs.tut.fi/~jkorpela/qattr.html>

          Also, somebody owns remotedomain.co m - example.com has been reserved for
          examples of this nature.

          [color=blue]
          > But I thought it might be a good idea to verify the user is wants to do it
          > (and didn't click on the link by accident), so I added the following
          > javascript:
          >
          >
          > <script language="JavaS cript">
          > function doit() {
          > if(confirm('Do you really want to do that thing?'))
          > { decision.value =[/color]

          What does 'decision' refer to?

          [color=blue]
          > 'http://www.remotedomai n.com/cgi-bin/task.cgi?identi fier;' submit(); }[/color]

          What does 'submit()' refer to? And don't you want the preceding ;' to be
          ';?


          [snip][color=blue]
          > <a href="javascrip t:doit()">Do That Thing</a>[/color]

          The FAQ explains why this is a bad idea:

          <URL:http://jibbering.com/faq/#FAQ4_24>

          [color=blue]
          > The alert box pops up fine, but I've tried a bunch of different things and
          > I can't get the link to work when the user clicks on the OK button.[/color]

          You want something like this:

          <form action="http://www.example.com/cgi-bin/task.cgi?identi fier"
          method="post" onsubmit="retur n confirm('Are you sure?');">
          <input type="submit" value="Do that thing">
          </form>

          If you are concerned about the fact that you have a button instead of a
          link, please read this:

          <URL:http://tom.me.uk/scripting/submit.asp>


          --
          Jim Dabell

          Comment

          • Slartybartfast

            #6
            Re: Action From An Alert Box

            Thank you guys. It works like a charm.

            As for the POST vs. Get; it makes sense. I'm looking into it. Thanks. I


            Comment

            Working...