change button text and submit

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

    change button text and submit

    I am trying to create a small javascript to change the button text and
    then submit it and do all kinds of form validations.
    So I have a button with the value "Save", when the button is clicked
    it should change into "Are you sure" and when you then click the
    button the form must be submitted. I know this is possible using a
    simple dialog box but I want to this it this way. This is what I
    already have, if you have any suggestions please reply..

    <head>
    <script language="javas cript">
    <!--

    function confirmButton() {
    if (document.frm1. button1.value = "Save"){
    document.frm1.b utton1.value = "Are you Sure"
    }
    else if (document.frm1. button1.value = "Are you sure"){
    document.frm1.b utton1.value = "Save")
    }
    //-->
    </script>
    </head>
    <body>
    <form name=frm1 action="blabla. asp">
    <input type=hidden>
    <input type="submit" value="Save">
    </form>
    <body>
  • McKirahan

    #2
    Re: change button text and submit

    "Christiaan " <info@asperium. com> wrote in message
    news:4e50bb1b.0 401061213.7caf1 966@posting.goo gle.com...[color=blue]
    > I am trying to create a small javascript to change the button text and
    > then submit it and do all kinds of form validations.
    > So I have a button with the value "Save", when the button is clicked
    > it should change into "Are you sure" and when you then click the
    > button the form must be submitted. I know this is possible using a
    > simple dialog box but I want to this it this way. This is what I
    > already have, if you have any suggestions please reply..
    >
    > <head>
    > <script language="javas cript">
    > <!--
    >
    > function confirmButton() {
    > if (document.frm1. button1.value = "Save"){
    > document.frm1.b utton1.value = "Are you Sure"
    > }
    > else if (document.frm1. button1.value = "Are you sure"){
    > document.frm1.b utton1.value = "Save")
    > }
    > //-->
    > </script>
    > </head>
    > <body>
    > <form name=frm1 action="blabla. asp">
    > <input type=hidden>
    > <input type="submit" value="Save">
    > </form>
    > <body>[/color]

    Clicking a button basically means "OK" so if you ask "Are you sure?" how
    will they not say "OK"?


    Here's a solution but with the "confirm" dialog that you don't want:

    <html>
    <head>
    <title>r-u-sure.htm</title>
    <script language="javas cript" type="text/javascript">
    <!--
    function confirmButton() {
    // { validations here }
    if (!confirm("Are you sure?","")) return false;
    return true;
    }
    //-->
    </script>
    </head>
    <body>
    <form name="frm1" action="blabla. asp" method="post" onsubmit="retur n
    confirmButton() ">
    <input type="submit" value="Save">
    </form>
    <body>
    </body>
    </html>

    Here's a solution based on your code but without a way to not say "OK".

    <html>
    <head>
    <title>r_u_sure .htm</title>
    <script language="javas cript" type="text/javascript">
    <!--
    function confirmButton() {
    var form = document.frm1;
    if (form.button1.v alue == "Save") {
    form.button1.va lue = "Are you sure?";
    } else {
    form.submit();
    }
    }
    //-->
    </script>
    </head>
    <body>
    <form name="frm1" action="blabla. asp" method="post">
    <input type="button" name="button1" value="Save" onclick="confir mButton()">
    </form>
    <body>
    </body>
    </html>


    Comment

    • HikksNotAtHome

      #3
      Re: change button text and submit

      In article <QXFKb.760357$T r4.2159619@attb i_s03>, "McKirahan"
      <News@McKirahan .com> writes:
      [color=blue]
      >Here's a solution based on your code but without a way to not say "OK".
      >
      >
      ><head>
      ><title>r_u_sur e.htm</title>
      ><script language="javas cript" type="text/javascript">
      ><!--
      >function confirmButton() {
      > var form = document.frm1;
      > if (form.button1.v alue == "Save") {
      > form.button1.va lue = "Are you sure?";
      > } else {
      > form.submit();
      > }
      >}[/color]

      The language attribute is not needed, nor are the HTML Entities for comments.

      But, why does that not allow for the user to confirm? It requires two clicks of
      the button, if you want to cancel it, simply don't click it again.
      --
      Randy

      Comment

      • HikksNotAtHome

        #4
        Re: change button text and submit

        In article <4e50bb1b.04010 61213.7caf1966@ posting.google. com>, info@asperium.c om
        (Christiaan) writes:
        [color=blue]
        >I am trying to create a small javascript to change the button text and
        >then submit it and do all kinds of form validations.
        >So I have a button with the value "Save", when the button is clicked
        >it should change into "Are you sure" and when you then click the
        >button the form must be submitted. I know this is possible using a
        >simple dialog box but I want to this it this way. This is what I
        >already have, if you have any suggestions please reply..
        >
        ><head>
        ><script language="javas cript">[/color]

        language is deprecated, use type="text/javascript" instead
        [color=blue]
        ><!--[/color]

        The HTML Entity for a comment is no longer needed.
        [color=blue]
        >
        > function confirmButton() {
        > if (document.frm1. button1.value = "Save"){
        > document.frm1.b utton1.value = "Are you Sure"
        > }
        > else if (document.frm1. button1.value = "Are you sure"){
        > document.frm1.b utton1.value = "Save")
        > }[/color]

        Using = sets a property, == compares them, === compares type as well as value.

        inside your if statements, you need == instead of =.
        So, it will always result in the first one executing.
        There is also no need for the second if statement.
        The only way it will make it to the else is if the value has been changed, so
        theres no point in testing it again.

        function confirmButton() {
        if (document.frm1. button1.value == "Save")
        {
        document.frm1.b utton1.value = "Are you Sure"
        }
        else
        {
        document.frm1.s ubmit();
        }
        }

        --
        Randy

        Comment

        • Jeff North

          #5
          Re: change button text and submit

          On 6 Jan 2004 12:13:10 -0800, in comp.lang.javas cript
          info@asperium.c om (Christiaan) wrote:
          [color=blue]
          >| I am trying to create a small javascript to change the button text and
          >| then submit it and do all kinds of form validations.
          >| So I have a button with the value "Save", when the button is clicked
          >| it should change into "Are you sure" and when you then click the
          >| button the form must be submitted. I know this is possible using a
          >| simple dialog box but I want to this it this way. This is what I
          >| already have, if you have any suggestions please reply..
          >|
          >| <head>
          >| <script language="javas cript">
          >| <!--
          >|
          >| function confirmButton() {
          >| if (document.frm1. button1.value = "Save"){
          >| document.frm1.b utton1.value = "Are you Sure"
          >| }
          >| else if (document.frm1. button1.value = "Are you sure"){
          >| document.frm1.b utton1.value = "Save")
          >| }
          >| //-->
          >| </script>
          >| </head>
          >| <body>
          >| <form name=frm1 action="blabla. asp">
          >| <input type=hidden>
          >| <input type="submit" value="Save">
          >| </form>
          >| <body>[/color]

          You might want to try:

          <form name="frm1" action="blabla. asp" onsubmit="retur n
          confirmButton() ;">
          ....
          </form>

          function confirmButton()
          {
          if( document.frm1.b utton1.value == "Save") {
          document.frm1.b utton1.value = "Are you Sure";
          return false;
          } else {
          document.frm1.b utton1.value = "Save";
          return true;
          }
          }
          ---------------------------------------------------------------
          jnorth@yourpant sbigpond.net.au : Remove your pants to reply
          ---------------------------------------------------------------

          Comment

          Working...