JavaScript Button OnClick Disable and Change Value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kestrel
    Recognized Expert Top Contributor
    • Jul 2006
    • 1071

    JavaScript Button OnClick Disable and Change Value

    i need a button, that onclick changes value to "Sending" and disables so the cant click it again
    Heres what i have
    Code:
    <input type="button" value="Submit" onclick="this.disabled=1; this.form.submit();">
    but i cant seem to make
    Code:
    this.value=Sending;
    to work with the other two scripts in the button.

    Is it possible?

    --Thanks
  • kestrel
    Recognized Expert Top Contributor
    • Jul 2006
    • 1071

    #2
    NVM i figured it out
    sorry

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      How did you get it to work?
      I'm having a similar problem. The button disables but it will not send the postback request.

      Comment

      • equazcion
        New Member
        • Mar 2007
        • 4

        #4
        I wouldn't do this in-line, but here you go as a function. You'll need to name the form also, by the way.

        Put this in your HTML header:
        Code:
        <script>
        function submitted(){[INDENT]button1 = getElementsByName("submit")[0];
        form1 = getElementsByName("--place form name here--")[0];
        if (button1.value == "Submit"){[INDENT]button1.value="Sending...";
        form1.submit();}[/INDENT]else {return false;}[/INDENT]}
        </script>
        And here's the button code:
        Code:
        <input name="submit" type="button" value="Submit" 
        onclick="return submitted();">
        Last edited by equazcion; Mar 8 '07, 06:50 AM. Reason: felt like it

        Comment

        • marcioavmartins
          New Member
          • Apr 2007
          • 1

          #5
          Hello!

          Well i modified the function and become that way:

          function disableSubmit(b otao,formulario ){

          document.getEle mentById(botao) .value = "Processando... ";

          document.getEle mentById(botao) .disabled = true;
          document.formul ario.submit();
          }

          and in the form, put in the form tag the following onSubmit satatement as follows:

          <form method="post" name="formViage m" onSubmit=disabl eSubmit("gravar Apenas","formVi agem");>

          This way, the button be disabled and the form is submitted correctly (the user cannot press more than one time if the form is submitting).

          []s
          Márcio

          Comment

          Working...