objects/forms

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

    objects/forms

    How can I code a button to change the values in multiple text fields? Do I
    use an && or something similar? It would be very nice to see an example,
    because I cannot find this in the tutorials that I have been reading.

    --



  • Mick White

    #2
    Re: objects/forms

    sayimsick wrote:
    [color=blue]
    > How can I code a button to change the values in multiple text fields? Do I
    > use an && or something similar? It would be very nice to see an example,
    > because I cannot find this in the tutorials that I have been reading.
    >[/color]
    .... onclick="a.valu e='A';b.value=' B';c.value='C'; ....">

    Assuming textfields are in same form as the button, and that the
    textfields are named "a", "b" and "c".

    Mick

    Comment

    • kaeli

      #3
      Re: objects/forms

      In article <V-mdnTqaVdizz0vdR Vn-vw@comcast.com> , sayimsick@comca st.net
      enlightened us with...[color=blue]
      > How can I code a button to change the values in multiple text fields? Do I
      > use an && or something similar? It would be very nice to see an example,
      > because I cannot find this in the tutorials that I have been reading.
      >
      >[/color]

      What do you mean?
      Can you clarify the question?

      --
      --
      ~kaeli~
      Shotgun wedding: A case of wife or death.



      Comment

      • sayimsick

        #4
        Re: objects/forms

        Thanks, I'll try this later!

        "Mick White" <mwhite13@BOGUS rochester.rr.co m> wrote in message
        news:jLBBc.3691 71$M3.38290@twi ster.nyroc.rr.c om...[color=blue]
        > sayimsick wrote:
        >[color=green]
        > > How can I code a button to change the values in multiple text fields?[/color][/color]
        Do I[color=blue][color=green]
        > > use an && or something similar? It would be very nice to see an[/color][/color]
        example,[color=blue][color=green]
        > > because I cannot find this in the tutorials that I have been reading.
        > >[/color]
        > ... onclick="a.valu e='A';b.value=' B';c.value='C'; ....">
        >
        > Assuming textfields are in same form as the button, and that the
        > textfields are named "a", "b" and "c".
        >
        > Mick[/color]


        Comment

        • sayimsick

          #5
          Re: objects/forms

          Okay, I have the javascript in the same form as my text fields, and the
          fields are correctly named. When I push the button on the web page, nothing
          happens. Can you help me further? Thank you very much. (I'm using a PHP
          loop to generate the part after onClick, and that is why I have some empty
          values)
          Each of the fields that will be manipulated is a text (<input type='text'
          ....)
          <script language="JavaS cript"><!--

          if (window.print)

          document.write( "<input type='button' value='This week is next week'
          onClick=sun10.v alue='';sun11.v alue='hi';sun12 .value='hi';sun 13.value='';>") ;

          //--></script>


          "Mick White" <mwhite13@BOGUS rochester.rr.co m> wrote in message
          news:jLBBc.3691 71$M3.38290@twi ster.nyroc.rr.c om...[color=blue]
          > sayimsick wrote:
          >[color=green]
          > > How can I code a button to change the values in multiple text fields?[/color][/color]
          Do I[color=blue][color=green]
          > > use an && or something similar? It would be very nice to see an[/color][/color]
          example,[color=blue][color=green]
          > > because I cannot find this in the tutorials that I have been reading.
          > >[/color]
          > ... onclick="a.valu e='A';b.value=' B';c.value='C'; ....">
          >
          > Assuming textfields are in same form as the button, and that the
          > textfields are named "a", "b" and "c".
          >
          > Mick[/color]


          Comment

          • Mick White

            #6
            Re: objects/forms

            sayimsick wrote:

            [color=blue]
            > Each of the fields that will be manipulated is a text (<input type='text'
            > ...)[/color]

            See example:



            <form>
            <input name="sun13" type="text" value="stuff">
            <input name="sun11" type="text" value="stuff">
            <input name="sun12" type="text" value="stuff">
            <input name="sun10" type="text" value="stuff">
            <script type="text/JavaScript">
            document.write( "<input type='button' value='This week is next week'
            onclick=\"sun10 .value='';sun11 .value='hi';sun 12.value='hi';s un13.value='';\ "[color=blue]
            >")[/color]
            </script>
            </form>

            Mick

            [color=blue]
            > "Mick White" <mwhite13@BOGUS rochester.rr.co m> wrote in message
            > news:jLBBc.3691 71$M3.38290@twi ster.nyroc.rr.c om...[/color]

            Comment

            • Lasse Reichstein Nielsen

              #7
              Re: objects/forms

              Mick White <mwhite13@BOGUS rochester.rr.co m> writes:
              [color=blue]
              > <form>[/color]

              (The action attribute is required in HTML 4)
              [color=blue]
              > <input name="sun13" type="text" value="stuff">[/color]
              ....[color=blue]
              > <script type="text/JavaScript">
              > document.write( "<input type='button' value='This week is next week'
              > onclick=\"sun10 .value='';sun11 .value='hi';sun 12.value='hi';s un13.value='';\ "[/color]

              There are browsers where this will fail because the properties of the
              containing form element is not added to the scope chain of the onclick
              handler. A safer method is:
              onclick=\"var f=this.form.ele ments;f.sun10.v alue='',f.sun11 .value='hi' ...

              /L
              --
              Lasse Reichstein Nielsen - lrn@hotpop.com
              DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
              'Faith without judgement merely degrades the spirit divine.'

              Comment

              • Mick White

                #8
                Re: objects/forms

                Lasse Reichstein Nielsen wrote:
                [color=blue]
                > Mick White <mwhite13@BOGUS rochester.rr.co m> writes:[/color]
                [color=blue]
                >[color=green]
                >><script type="text/JavaScript">
                >> document.write( "<input type='button' value='This week is next week'
                >> onclick=\"sun10 .value='';sun11 .value='hi';sun 12.value='hi';s un13.value='';\ "[/color]
                >
                >
                > There are browsers where this will fail because the properties of the
                > containing form element is not added to the scope chain of the onclick
                > handler. A safer method is:
                > onclick=\"var f=this.form.ele ments;f.sun10.v alue='',f.sun11 .value='hi' ...[/color]

                Yes, you're probably right. But I haven't found a browser that chokes on it.
                Mick
                [color=blue]
                > /L[/color]

                Comment

                • sayimsick

                  #9
                  Re: objects/forms

                  hmmmm something is still wrong, even if I use your exact script, and I know
                  that the script should work because it works on that page.
                  Does it matter that some fields do not exist that the button refers to?
                  Does it matter that the name is in single quotes? Does it matter that it is
                  separated by a few rows and the submit button? Did I put a semicolon in the
                  wrong spot? Thank you very much for helping me, even though I'm sure that
                  I'm a frustrating beginner to you.

                  //////////////////////////////////////////////////////
                  This is what I have in php, and then I will show you how it gets translated:

                  echo"<TD><input name='$sun_one' type='text' value='$sun1[$i]'></TD>";

                  /*some table rows are here]*/

                  <TR>
                  <TD>
                  echo"javabutton is $javabutton<br>
                  <script language=\"Java Script\"><!--
                  document.write( \"<input type='button' value='This week is next week'
                  onclick=\\\"$ja vabutton\\\">\" )
                  //--></script>
                  </TD>
                  </TR>
                  </TABLE>";

                  Here is the translated web page exerpt:

                  <TD><input name='sun12' type='text' value='34'></TD>
                  <script language="JavaS cript"><!--

                  javabutton is
                  sun10.value=''; sun11.value='hi ';sun12.value=' hi';sun13.value ='';<br>

                  document.write( "<input type='button' value='This week is next week'
                  onclick=\"sun10 .value='';sun11 .value='hi';sun 12.value='hi';s un13.value='';\ "[color=blue]
                  >")[/color]

                  //--></script>


                  "Mick White" <mwhite13@BOGUS rochester.rr.co m> wrote in message
                  news:m2VBc.1082 18$j24.102953@t wister.nyroc.rr .com...[color=blue]
                  > sayimsick wrote:
                  >
                  >[color=green]
                  > > Each of the fields that will be manipulated is a text (<input[/color][/color]
                  type='text'[color=blue][color=green]
                  > > ...)[/color]
                  >
                  > See example:
                  >
                  > http://www.mickweb.com/demo/dynamicButton.html
                  >
                  > <form>
                  > <input name="sun13" type="text" value="stuff">
                  > <input name="sun11" type="text" value="stuff">
                  > <input name="sun12" type="text" value="stuff">
                  > <input name="sun10" type="text" value="stuff">
                  > <script type="text/JavaScript">
                  > document.write( "<input type='button' value='This week is next week'
                  >[/color]
                  onclick=\"sun10 .value='';sun11 .value='hi';sun 12.value='hi';s un13.value='';\ "[color=blue][color=green]
                  > >")[/color]
                  > </script>
                  > </form>
                  >
                  > Mick
                  >
                  >[color=green]
                  > > "Mick White" <mwhite13@BOGUS rochester.rr.co m> wrote in message
                  > > news:jLBBc.3691 71$M3.38290@twi ster.nyroc.rr.c om...[/color][/color]


                  Comment

                  • Mick White

                    #10
                    Re: objects/forms

                    sayimsick wrote:
                    [color=blue]
                    > hmmmm something is still wrong, even if I use your exact script, and I know
                    > that the script should work because it works on that page.
                    > Does it matter that some fields do not exist that the button refers to?[/color]

                    Absolutely. You can test for this in PHP, or in js.
                    - if(sun10 && sun11 && ...)
                    [color=blue]
                    > Does it matter that the name is in single quotes?[/color]

                    NO

                    Does it matter that it is[color=blue]
                    > separated by a few rows and the submit button?[/color]

                    No, as long as the textboxes and form controls are within the same form.
                    And within <form> </form> pair.

                    Did I put a semicolon in the[color=blue]
                    > wrong spot?[/color]
                    Looks OK
                    Mick

                    Comment

                    • sayimsick

                      #11
                      Re: objects/forms

                      Thank you VERY much. The button works perfectly now.

                      "Mick White" <mwhite13@BOGUS rochester.rr.co m> wrote in message
                      news:jIXBc.1089 71$j24.79590@tw ister.nyroc.rr. com...[color=blue]
                      > sayimsick wrote:
                      >[color=green]
                      > > hmmmm something is still wrong, even if I use your exact script, and I[/color][/color]
                      know[color=blue][color=green]
                      > > that the script should work because it works on that page.
                      > > Does it matter that some fields do not exist that the button refers to?[/color]
                      >
                      > Absolutely. You can test for this in PHP, or in js.
                      > - if(sun10 && sun11 && ...)
                      >[color=green]
                      > > Does it matter that the name is in single quotes?[/color]
                      >
                      > NO
                      >
                      > Does it matter that it is[color=green]
                      > > separated by a few rows and the submit button?[/color]
                      >
                      > No, as long as the textboxes and form controls are within the same form.
                      > And within <form> </form> pair.
                      >
                      > Did I put a semicolon in the[color=green]
                      > > wrong spot?[/color]
                      > Looks OK
                      > Mick
                      >[/color]


                      Comment

                      Working...