Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    May 2004
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    enter into textfield when checkbox is checked

    I have a load of checkboxes with the value of different email addresses on them. Is there any script that when a user checks one or more of these checkboxes it would enter the email address into a textfield which is located on the same page.

    many thanks

    dakey

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Posts
    626
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Something like this?
    Code:
    <html>
     <head>
      <title>Email Add</title>
       <script type="text/javascript">
         function doIt(obj)
          {
           document.myform.txt1.value+=" "+obj.value
          }
       </script>
     </head>
     <body>
       <form name="myform">
         <input type="checkbox" value="me@mail.com" onClick="doIt(this)">me@mail.com<br>
         <input type="checkbox" value="you@mail.com" onClick="doIt(this)">you@mail.com<br>
         <input type="checkbox" value="us@mail.com" onClick="doIt(this)">us@mail.com<br>
         <input type="text" name="txt1" size="30">
       </form>
     </body>
    </html>

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,042
    Thanks
    0
    Thanked 250 Times in 246 Posts
    That will add the same email address continually for every click even if you unchecked the checkboxes.

    You may want to build around on this:
    Code:
    <html>
     <head>
      <title>Email Add</title>
       <script type="text/javascript">
         function doIt(obj)
          {
            if (obj.checked){
               obj.form.txt1.value += ((obj.form.txt1.value!='') ? ',':'') + obj.value;
            }
            else {
               obj.form.txt1.value = obj.form.txt1.value.replace(new RegExp(",*" + obj.value, "g"), '').replace(/^,*/, '');
            } 
          }
       </script>
     </head>
     <body>
       <form name="myform">
         <input type="checkbox" value="me@mail.com" onClick="doIt(this)">me@mail.com<br>
         <input type="checkbox" value="you@mail.com" onClick="doIt(this)">you@mail.com<br>
         <input type="checkbox" value="us@mail.com" onClick="doIt(this)">us@mail.com<br>
         <input type="text" name="txt1" size="60">
       </form>
     </body>
    </html>

  • #4
    New to the CF scene
    Join Date
    May 2004
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thankyou that is perfect, works like a dream..


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •