listing words in a textbox using checkboxes

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

    #1

    listing words in a textbox using checkboxes

    Hello,
    Is it possible to dynamically update a textbox with words chosen from a
    list using form checkboxes and javascript?
    Gary


  • Ivo

    #2
    Re: listing words in a textbox using checkboxes

    "Gary" <g.moore@shaw.c a> wrote in message
    news:IVgYb.5371 54$ts4.42209@pd 7tw3no...[color=blue]
    > Hello,
    > Is it possible to dynamically update a textbox with words chosen from a
    > list using form checkboxes and javascript?
    > Gary[/color]

    I 'm not sure I understand what you want. The following would add (or
    remove) the words to the output in the order the checkboxes are clicked. It
    is not the only possibility.
    <script type="text/javascript">
    function listwords(c,n) {
    s=document.f.ou t.value;
    if (c.checked) {
    if (s.indexOf(n)<0 ) s+=' '+n;
    } else {
    s=document.f.ou t.value.replace (' '+n,'');
    }
    document.f.out. value=s;
    }
    </script>
    <form name="f" method="get" onsubmit="retur n false">
    <input type="text" value="" name="out"><br>
    <input type="checkbox" name="check1"
    onclick="listwo rds(this,'Word' )">Word<br>
    <input type="checkbox" name="check1"
    onclick="listwo rds(this,'Type' )">Type<br>
    <input type="checkbox" name="check1"
    onclick="listwo rds(this,'Other ')">Other<br>
    </form>


    Comment

    • Gary

      #3
      Re: listing words in a textbox using checkboxes


      Ivo wrote:[color=blue]
      > "Gary" <g.moore@shaw.c a> wrote in message
      > news:IVgYb.5371 54$ts4.42209@pd 7tw3no...[color=green]
      >> Hello,
      >> Is it possible to dynamically update a textbox with words chosen
      >> from a list using form checkboxes and javascript?
      >> Gary[/color]
      >
      > I 'm not sure I understand what you want. The following would add (or
      > remove) the words to the output in the order the checkboxes are
      > clicked. It is not the only possibility.
      > <script type="text/javascript">
      > function listwords(c,n) {
      > s=document.f.ou t.value;
      > if (c.checked) {
      > if (s.indexOf(n)<0 ) s+=' '+n;
      > } else {
      > s=document.f.ou t.value.replace (' '+n,'');
      > }
      > document.f.out. value=s;
      > }
      > </script>
      > <form name="f" method="get" onsubmit="retur n false">
      > <input type="text" value="" name="out"><br>
      > <input type="checkbox" name="check1"
      > onclick="listwo rds(this,'Word' )">Word<br>
      > <input type="checkbox" name="check1"
      > onclick="listwo rds(this,'Type' )">Type<br>
      > <input type="checkbox" name="check1"
      > onclick="listwo rds(this,'Other ')">Other<br>
      > </form>[/color]

      Ivo,
      That's exactly what I wanted! Thank-you for time and effort. I googled for
      hours and couldn't find anything remotely related and you mention other
      possibilities?
      Thanks again!
      Gary


      Comment

      • Gary

        #4
        Re: listing words in a textbox using checkboxes

        Ivo wrote:[color=blue]
        > "Gary" <g.moore@shaw.c a> wrote in message
        > news:IVgYb.5371 54$ts4.42209@pd 7tw3no...[color=green]
        >> Hello,
        >> Is it possible to dynamically update a textbox with words chosen
        >> from a list using form checkboxes and javascript?
        >> Gary[/color]
        >
        > I 'm not sure I understand what you want. The following would add (or
        > remove) the words to the output in the order the checkboxes are
        > clicked. It is not the only possibility.
        > <script type="text/javascript">
        > function listwords(c,n) {
        > s=document.f.ou t.value;
        > if (c.checked) {
        > if (s.indexOf(n)<0 ) s+=' '+n;
        > } else {
        > s=document.f.ou t.value.replace (' '+n,'');
        > }
        > document.f.out. value=s;
        > }
        > </script>
        > <form name="f" method="get" onsubmit="retur n false">
        > <input type="text" value="" name="out"><br>
        > <input type="checkbox" name="check1"
        > onclick="listwo rds(this,'Word' )">Word<br>
        > <input type="checkbox" name="check1"
        > onclick="listwo rds(this,'Type' )">Type<br>
        > <input type="checkbox" name="check1"
        > onclick="listwo rds(this,'Other ')">Other<br>
        > </form>[/color]

        Would it be to much of a bother to ask how I can extend that script one
        further? Say I wanted to take a second list of words and only allow the
        option of inserting one word from that list in front of the list of words
        inserted into the textbox using radio buttons ?
        Gary


        Comment

        • Ivo

          #5
          Re: listing words in a textbox using checkboxes

          "Gary" <g.moore@shaw.c a> wrote in message
          news:NmCYb.5501 16$ts4.306481@p d7tw3no...[color=blue]
          > Ivo wrote:[color=green]
          > > "Gary" <g.moore@shaw.c a> wrote in message
          > > news:IVgYb.5371 54$ts4.42209@pd 7tw3no...[color=darkred]
          > >> Hello,
          > >> Is it possible to dynamically update a textbox with words chosen
          > >> from a list using form checkboxes and javascript?
          > >> Gary[/color]
          > > (...)[/color]
          > Would it be to much of a bother to ask how I can extend that script one
          > further? Say I wanted to take a second list of words and only allow the
          > option of inserting one word from that list in front of the list of words
          > inserted into the textbox using radio buttons ?
          > Gary
          >[/color]
          It 's isn't getting any clearer what you are after, but this does as
          requested. In the current design, all words have to be unique. I don't know
          if that is a problem. and you need to specify the words in an array at the
          start of the script, a bit clumsy. But with that, all that was needed was to
          add two short "for" loops, the first removing anything like a radio'ed word,
          the second adding the currently selected word. The process could be repeated
          for other groups of words.

          <script type="text/javascript">
          var oneOf=new Array('One','Wo rd','Only');
          function listwords(c) {n=c.value;
          s=document.f.ou t.value;
          for(i=0;i<oneOf .length;i++) s=s.replace(' '+oneOf[i],'');
          for(i=0;i<docum ent.f.radio1.le ngth;i++) {
          a=document.f.ra dio1[i]; if(a.checked)s+ =' '+a.value;
          }
          if (c.checked) {
          if (s.indexOf(n)<0 ) s+=' '+n;
          } else {
          s=document.f.ou t.value.replace (' '+n,'');
          }
          document.f.out. value=s;
          }
          </script>
          <form name="f" method="get" onsubmit="retur n false">
          <input type="text" value="" name="out"><br>
          <input type="checkbox" name="check1" value="More"
          onclick="listwo rds(this)">More <br>
          <input type="checkbox" name="check2" value="Than"
          onclick="listwo rds(this)">Than <br>
          <input type="checkbox" name="check3" value="Before"
          onclick="listwo rds(this)">Befo re<br>

          <input type="radio" name="radio1" value="One"
          onclick="listwo rds(this)">One< br>
          <input type="radio" name="radio1" value="Word"
          onclick="listwo rds(this)">Word <br>
          <input type="radio" name="radio1" value="Only"
          onclick="listwo rds(this)">Only <br>

          </form>


          Comment

          • Gary

            #6
            Re: listing words in a textbox using checkboxes

            Ivo wrote:[color=blue]
            > "Gary" <g.moore@shaw.c a> wrote in message
            > news:NmCYb.5501 16$ts4.306481@p d7tw3no...[color=green]
            >> Ivo wrote:[color=darkred]
            >>> "Gary" <g.moore@shaw.c a> wrote in message
            >>> news:IVgYb.5371 54$ts4.42209@pd 7tw3no...
            >>>> Hello,
            >>>> Is it possible to dynamically update a textbox with words chosen
            >>>> from a list using form checkboxes and javascript?
            >>>> Gary
            >>> (...)[/color]
            >> Would it be to much of a bother to ask how I can extend that script
            >> one further? Say I wanted to take a second list of words and only
            >> allow the option of inserting one word from that list in front of
            >> the list of words inserted into the textbox using radio buttons ?
            >> Gary
            >>[/color]
            > It 's isn't getting any clearer what you are after, but this does as
            > requested. In the current design, all words have to be unique. I
            > don't know if that is a problem. and you need to specify the words in
            > an array at the start of the script, a bit clumsy. But with that, all
            > that was needed was to add two short "for" loops, the first removing
            > anything like a radio'ed word, the second adding the currently
            > selected word. The process could be repeated for other groups of
            > words.[/color]

            Ivo,
            That is one nice revision! I don't think I expressed my needs as well as I
            might have, but hopefully I will be able to modify the script without the
            need to pester here. Thanks again for your help!
            Gary


            Comment

            • Gary

              #7
              Re: listing words in a textbox using checkboxes

              Ivo wrote:[color=blue]
              > "Gary" <g.moore@shaw.c a> wrote in message
              > news:NmCYb.5501 16$ts4.306481@p d7tw3no...[color=green]
              >> Ivo wrote:[color=darkred]
              >>> "Gary" <g.moore@shaw.c a> wrote in message
              >>> news:IVgYb.5371 54$ts4.42209@pd 7tw3no...
              >>>> Hello,
              >>>> Is it possible to dynamically update a textbox with words chosen
              >>>> from a list using form checkboxes and javascript?
              >>>> Gary
              >>> (...)[/color]
              >> Would it be to much of a bother to ask how I can extend that script
              >> one further? Say I wanted to take a second list of words and only
              >> allow the option of inserting one word from that list in front of
              >> the list of words inserted into the textbox using radio buttons ?
              >> Gary
              >>[/color]
              > It 's isn't getting any clearer what you are after, but this does as
              > requested. In the current design, all words have to be unique. I
              > don't know if that is a problem. and you need to specify the words in
              > an array at the start of the script, a bit clumsy. But with that, all
              > that was needed was to add two short "for" loops, the first removing
              > anything like a radio'ed word, the second adding the currently
              > selected word. The process could be repeated for other groups of
              > words.
              >
              > <script type="text/javascript">
              > var oneOf=new Array('One','Wo rd','Only');
              > function listwords(c) {n=c.value;
              > s=document.f.ou t.value;
              > for(i=0;i<oneOf .length;i++) s=s.replace(' '+oneOf[i],'');
              > for(i=0;i<docum ent.f.radio1.le ngth;i++) {
              > a=document.f.ra dio1[i]; if(a.checked)s+ =' '+a.value;
              > }
              > if (c.checked) {
              > if (s.indexOf(n)<0 ) s+=' '+n;
              > } else {
              > s=document.f.ou t.value.replace (' '+n,'');
              > }
              > document.f.out. value=s;
              > }
              > </script>
              > <form name="f" method="get" onsubmit="retur n false">
              > <input type="text" value="" name="out"><br>
              > <input type="checkbox" name="check1" value="More"
              > onclick="listwo rds(this)">More <br>
              > <input type="checkbox" name="check2" value="Than"
              > onclick="listwo rds(this)">Than <br>
              > <input type="checkbox" name="check3" value="Before"
              > onclick="listwo rds(this)">Befo re<br>
              >
              > <input type="radio" name="radio1" value="One"
              > onclick="listwo rds(this)">One< br>
              > <input type="radio" name="radio1" value="Word"
              > onclick="listwo rds(this)">Word <br>
              > <input type="radio" name="radio1" value="Only"
              > onclick="listwo rds(this)">Only <br>
              >
              > </form>[/color]

              Ivo,
              It doesn't look like that will work for me after all, if I haven't worn out
              my welcome would it be possible for you to show me how I can "surround" the
              list of words created from the checkboxes with "predefined " text selected
              with radio buttons? i.e.:

              words selected with checkboxes = one, two, three

              <text from radio1 here>one, two, three</end text from radio1>
              or
              <text from radio2 here>one,two,th ree</end text from radio2>
              Thanks in advance
              Gary


              Comment

              • Ivo

                #8
                Re: listing words in a textbox using checkboxes

                "Gary" <g.moore@shaw.c a> wrote in message
                news:2xiZb.5578 86$JQ1.437459@p d7tw1no...[color=blue]
                > Ivo wrote:[color=green]
                > > "Gary" <g.moore@shaw.c a> wrote in message
                > > news:NmCYb.5501 16$ts4.306481@p d7tw3no...[color=darkred]
                > >> Ivo wrote:
                > >>> "Gary" <g.moore@shaw.c a> wrote in message
                > >>> news:IVgYb.5371 54$ts4.42209@pd 7tw3no...[/color][/color]
                > would it be possible for you to show me how I can "surround" the
                > list of words created from the checkboxes with "predefined " text selected
                > with radio buttons? i.e.:
                >
                > words selected with checkboxes = one, two, three
                >
                > <text from radio1 here>one, two, three</end text from radio1>
                > or
                > <text from radio2 here>one,two,th ree</end text from radio2>[/color]

                There you are: function listwords version 3.0 below is really dirty: at each
                click of the mouse the contents in the output field is completely erased and
                rewritten. The order in which the boxes are checked no longer counts. I hope
                that doesn't hurt,
                Ivo

                <script type="text/javascript">
                function listwords(){
                s='';
                for(i=0;i<docum ent.f.elements. length;i++){
                a=document.f.el ements[i];
                if(a.type=='che ckbox'&&a.check ed)
                s+=' '+a.value;
                }
                for(i=0;i<docum ent.f.radio1.le ngth;i++){
                a=document.f.ra dio1[i];
                if(a.checked){
                b=a.value.split ('|');
                s=b[0]+s+' '+b[1];
                }
                }
                document.f.out. value=s;
                }
                </script>
                <form name="f" method="get" onsubmit="retur n false">
                <input type="text" value="" name="out"><br>
                <input type="checkbox" name="check1" value="More"
                onclick="listwo rds()">More<br>
                <input type="checkbox" name="check2" value="Than"
                onclick="listwo rds()">Than<br>
                <input type="checkbox" name="check3" value="Before"
                onclick="listwo rds()">Before<b r>
                <input type="radio" name="radio1" value="&lt;|&gt ;"
                onclick="listwo rds()">Symbol<b r>
                <input type="radio" name="radio1" value="alpha|om ega"
                onclick="listwo rds()">Word<br>
                <input type="radio" name="radio1" value="The first|will be the last."
                onclick="listwo rds()">Sentence <br>
                </form>


                Comment

                • Gary

                  #9
                  Re: listing words in a textbox using checkboxes

                  Ivo wrote:[color=blue]
                  > "Gary" <g.moore@shaw.c a> wrote in message
                  > news:2xiZb.5578 86$JQ1.437459@p d7tw1no...[color=green]
                  >> Ivo wrote:[color=darkred]
                  >>> "Gary" <g.moore@shaw.c a> wrote in message
                  >>> news:NmCYb.5501 16$ts4.306481@p d7tw3no...
                  >>>> Ivo wrote:
                  >>>>> "Gary" <g.moore@shaw.c a> wrote in message
                  >>>>> news:IVgYb.5371 54$ts4.42209@pd 7tw3no...[/color]
                  >> would it be possible for you to show me how I can "surround" the
                  >> list of words created from the checkboxes with "predefined " text
                  >> selected with radio buttons? i.e.:
                  >>
                  >> words selected with checkboxes = one, two, three
                  >>
                  >> <text from radio1 here>one, two, three</end text from radio1>
                  >> or
                  >> <text from radio2 here>one,two,th ree</end text from radio2>[/color]
                  >
                  > There you are: function listwords version 3.0 below is really dirty:
                  > at each click of the mouse the contents in the output field is
                  > completely erased and rewritten. The order in which the boxes are
                  > checked no longer counts. I hope that doesn't hurt,
                  > Ivo[/color]

                  Ivo,
                  Sorry about the delayed response, busy day yesterday.
                  Version 3.0 is almost picture perfect, for two of three radio buttons it
                  doesn't matter if the output field is erased and rewritten but for the
                  third radio button I need to allow the user to type text and choose
                  applicable checkboxes as required without erasing the text they have already
                  entered. Is that possible? As you have probably figured out my javascript
                  skills are extremely limited and I'm glad for the help you have offered
                  Gary
                  [color=blue]
                  >
                  > <script type="text/javascript">
                  > function listwords(){
                  > s='';
                  > for(i=0;i<docum ent.f.elements. length;i++){
                  > a=document.f.el ements[i];
                  > if(a.type=='che ckbox'&&a.check ed)
                  > s+=' '+a.value;
                  > }
                  > for(i=0;i<docum ent.f.radio1.le ngth;i++){
                  > a=document.f.ra dio1[i];
                  > if(a.checked){
                  > b=a.value.split ('|');
                  > s=b[0]+s+' '+b[1];
                  > }
                  > }
                  > document.f.out. value=s;
                  > }
                  > </script>
                  > <form name="f" method="get" onsubmit="retur n false">
                  > <input type="text" value="" name="out"><br>
                  > <input type="checkbox" name="check1" value="More"
                  > onclick="listwo rds()">More<br>
                  > <input type="checkbox" name="check2" value="Than"
                  > onclick="listwo rds()">Than<br>
                  > <input type="checkbox" name="check3" value="Before"
                  > onclick="listwo rds()">Before<b r>
                  > <input type="radio" name="radio1" value="&lt;|&gt ;"
                  > onclick="listwo rds()">Symbol<b r>
                  > <input type="radio" name="radio1" value="alpha|om ega"
                  > onclick="listwo rds()">Word<br>
                  > <input type="radio" name="radio1" value="The first|will be the last."
                  > onclick="listwo rds()">Sentence <br>
                  > </form>[/color]


                  Comment

                  • Gary

                    #10
                    Re: listing words in a textbox using checkboxes

                    I've added a function to select/deselect all checkboxes to the script below
                    in the form of:
                    function checkAll(field)
                    {
                    for (i = 0; i < field.length; i++)
                    field[i].checked = true ;
                    }

                    function uncheckAll(fiel d)
                    {
                    for (i = 0; i < field.length; i++)
                    field[i].checked = false ;
                    }


                    <input type="button" name="CheckAll" value="Check All"
                    onClick="checkA ll(document.f.c heck1)">
                    <input type="button" name="UnCheckAl l" value="Uncheck All"
                    onClick="unchec kAll(document.f .check1)">

                    my only problem is that the list items don't show in the textbox after using
                    the above function until a radio button is selected again. Have I missed
                    something in the original javascript that I can add to the "checkAll" and
                    "uncheckAll " functions that will update the textbox with all items in the
                    list?
                    TIA
                    Gary

                    Gary wrote:[color=blue]
                    > Ivo wrote:[color=green]
                    >> "Gary" <g.moore@shaw.c a> wrote in message
                    >> news:2xiZb.5578 86$JQ1.437459@p d7tw1no...[color=darkred]
                    >>> Ivo wrote:
                    >>>> "Gary" <g.moore@shaw.c a> wrote in message
                    >>>> news:NmCYb.5501 16$ts4.306481@p d7tw3no...
                    >>>>> Ivo wrote:
                    >>>>>> "Gary" <g.moore@shaw.c a> wrote in message
                    >>>>>> news:IVgYb.5371 54$ts4.42209@pd 7tw3no...
                    >>> would it be possible for you to show me how I can "surround" the
                    >>> list of words created from the checkboxes with "predefined " text
                    >>> selected with radio buttons? i.e.:
                    >>>
                    >>> words selected with checkboxes = one, two, three
                    >>>
                    >>> <text from radio1 here>one, two, three</end text from radio1>
                    >>> or
                    >>> <text from radio2 here>one,two,th ree</end text from radio2>[/color]
                    >>
                    >> There you are: function listwords version 3.0 below is really dirty:
                    >> at each click of the mouse the contents in the output field is
                    >> completely erased and rewritten. The order in which the boxes are
                    >> checked no longer counts. I hope that doesn't hurt,
                    >> Ivo[/color]
                    >
                    > Ivo,
                    > Sorry about the delayed response, busy day yesterday.
                    > Version 3.0 is almost picture perfect, for two of three radio buttons
                    > it doesn't matter if the output field is erased and rewritten but
                    > for the third radio button I need to allow the user to type text and
                    > choose applicable checkboxes as required without erasing the text
                    > they have already entered. Is that possible? As you have probably
                    > figured out my javascript skills are extremely limited and I'm glad
                    > for the help you have offered Gary
                    >[color=green]
                    >>
                    >> <script type="text/javascript">
                    >> function listwords(){
                    >> s='';
                    >> for(i=0;i<docum ent.f.elements. length;i++){
                    >> a=document.f.el ements[i];
                    >> if(a.type=='che ckbox'&&a.check ed)
                    >> s+=' '+a.value;
                    >> }
                    >> for(i=0;i<docum ent.f.radio1.le ngth;i++){
                    >> a=document.f.ra dio1[i];
                    >> if(a.checked){
                    >> b=a.value.split ('|');
                    >> s=b[0]+s+' '+b[1];
                    >> }
                    >> }
                    >> document.f.out. value=s;
                    >> }
                    >> </script>
                    >> <form name="f" method="get" onsubmit="retur n false">
                    >> <input type="text" value="" name="out"><br>
                    >> <input type="checkbox" name="check1" value="More"
                    >> onclick="listwo rds()">More<br>
                    >> <input type="checkbox" name="check2" value="Than"
                    >> onclick="listwo rds()">Than<br>
                    >> <input type="checkbox" name="check3" value="Before"
                    >> onclick="listwo rds()">Before<b r>
                    >> <input type="radio" name="radio1" value="&lt;|&gt ;"
                    >> onclick="listwo rds()">Symbol<b r>
                    >> <input type="radio" name="radio1" value="alpha|om ega"
                    >> onclick="listwo rds()">Word<br>
                    >> <input type="radio" name="radio1" value="The first|will be the last."
                    >> onclick="listwo rds()">Sentence <br>
                    >> </form>[/color][/color]


                    Comment

                    Working...