submit disable inside confirm alert

Discussion in 'Javascript' started by John, Jul 12, 2007.

  1. John

    John Guest

    I'd like to disable the submit button after the user clicks it once,
    but currently the submit button i'm using has a confirm alert. I've
    tried to nest the disable within the confirmIT script but it causes it
    to by pass the script completely. Any ideas?

    Thanks, John

    <script LANGUAGE="JavaScript">
    <!--
    function confirmIT()
    {
    var agree=confirm("To proceed, click OK.");
    if (agree)
    return true ;
    else
    return false ;
    }
    // -->
    </script>

    OR

    <script LANGUAGE="JavaScript">
    <!--
    function confirmIT()
    {
    var agree=confirm("To proceed, click OK.");
    if (agree)
    var thisBTN = document.getElementById('Submit');
    thisBTN.disabled = true
    return true ;
    else
    return false ;
    }
    // -->
    </script>
    John, Jul 12, 2007
    #1
    1. Advertising

  2. John

    David Mark Guest

    On Jul 12, 6:20 pm, John <> wrote:
    > I'd like to disable the submit button after the user clicks it once,
    > but currently the submit button i'm using has a confirm alert. I've
    > tried to nest the disable within the confirmIT script but it causes it
    > to by pass the script completely. Any ideas?
    >
    > Thanks, John
    >
    > <script LANGUAGE="JavaScript">


    Change that to:

    <script type="text/javascript">

    Note to others, I know text/javascript is deprecated, but invalid is
    worse than deprecated.

    Anyway, that isn't your problem.

    > <!--


    You don't need this.

    > function confirmIT()
    > {
    > var agree=confirm("To proceed, click OK.");
    > if (agree)
    > return true ;
    > else
    > return false ;}


    Why not just return the result of confirm?

    >
    > // -->


    Or this.

    > </script>
    >
    > OR
    >
    > <script LANGUAGE="JavaScript">
    > <!--
    > function confirmIT()
    > {
    > var agree=confirm("To proceed, click OK.");
    > if (agree)
    > var thisBTN = document.getElementById('Submit');
    > thisBTN.disabled = true
    > return true ;
    > else
    > return false ;}
    >
    > // -->
    > </script>


    You didn't post the script that calls this thing. Something tells me
    it is in the onclick handler of a form button, which then clumsily
    calls onsubmit if confirmIT gives the green light. If so, see a
    similar post from a few days ago, regarding a similar issue. If not,
    post the rest of the code.
    David Mark, Jul 12, 2007
    #2
    1. Advertising

  3. On Jul 12, 4:20 pm, John <> wrote:
    > I'd like to disable the submit button after the user clicks it once,


    So you call the function on click event of button ? Bad.. use submit
    event of form element:

    <form onsubmit="return confirmIT(this)" .. >
    ....
    <input type="submit">
    ....
    </form>

    > I've
    > tried to nest the disable within the confirmIT script but it causes it
    > to by pass the script completely. Any ideas?


    Yes, Change the function to:
    function confirmIT(form){
    if (confirm("To proceed, click OK.")){
    form.elements.Submit.disabled=true
    return true ;
    }else return false
    }
    scripts.contact, Jul 13, 2007
    #3
  4. John

    Darko Guest

    On Jul 13, 12:20 am, John <> wrote:
    > I'd like to disable the submit button after the user clicks it once,
    > but currently the submit button i'm using has a confirm alert. I've
    > tried to nest the disable within the confirmIT script but it causes it
    > to by pass the script completely. Any ideas?
    >
    > Thanks, John
    >
    > <script LANGUAGE="JavaScript">
    > <!--
    > function confirmIT()
    > {
    > var agree=confirm("To proceed, click OK.");
    > if (agree)
    > return true ;
    > else
    > return false ;}
    >
    > // -->
    > </script>
    >
    > OR
    >
    > <script LANGUAGE="JavaScript">
    > <!--
    > function confirmIT()
    > {
    > var agree=confirm("To proceed, click OK.");
    > if (agree)
    > var thisBTN = document.getElementById('Submit');
    > thisBTN.disabled = true
    > return true ;
    > else
    > return false ;}
    >
    > // -->
    > </script>


    Your code has one key problem - you don't have the blocks defined.
    if ( agree ) {
    var thisBTN = ...
    thisBTN.disabled = true;
    return true;
    } else
    return false;
    Darko, Jul 13, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ghafran Abbas
    Replies:
    0
    Views:
    4,193
    Ghafran Abbas
    Oct 12, 2004
  2. dev648237923

    Alert to confirm deletes in the new GridView control

    dev648237923, Nov 17, 2006, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    696
    Steven Cheng[MSFT]
    Nov 20, 2006
  3. Andy Fish

    alert() and confirm() function

    Andy Fish, Aug 14, 2003, in forum: Javascript
    Replies:
    7
    Views:
    132
    Jim Ley
    Aug 14, 2003
  4. Paul Oakfleet
    Replies:
    1
    Views:
    839
    Chris Riesbeck
    Sep 10, 2003
  5. Tasha's Dad

    Need to cancel a javascript alert/confirm box

    Tasha's Dad, Nov 4, 2004, in forum: Javascript
    Replies:
    5
    Views:
    300
    kaeli
    Nov 9, 2004
Loading...

Share This Page