Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: script help

  1. #1
    Join Date
    Jul 2007
    Posts
    59
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default script help

    i need to do check box that if i check it will add value to another textfield
    and i have about 3 check box and id check which one it will add value only not replace
    how can i do that thx

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Please restate your question more clearly, and supply example markup.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
      <script type="text/javascript">
        function map(f, a) {
          for(var i = 0, r = []; i < a.length; r.push(f(a, i++)));
          return r;
        }
    
        function filter(f, a) {
          for(var i = 0, r = []; i < a.length; f(a[i++], i) ? r.push(a[i]) : '');
          return r;
        }
    
        function catVals(els) {
          return map(function(el) { return el.value; }, filter(function(el) { return el.checked; }, els)).join("\r\n");
        }
      </script>
    </head>
    <body>
    <!-- ... -->
      <form action="">
        <textarea name="vals">
        </textarea>
        <input type="checkbox" value="cats" onclick="this.form.elements.vals.value = catVals(this.form.elements.chks);" name="chks">
        <input type="checkbox" value="dogs" onclick="this.form.elements.vals.value = catVals(this.form.elements.chks);" name="chks">
      </form>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I haven't looked over Twey's above response, which is probably good. I was just playing around with the idea as best that I understood it. I came up with this:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript">
    function cbox(box, tf){
    if(box.checked)
    box.form.elements[tf].value=isNaN(box.form.elements[tf].value-0)? box.value : (box.form.elements[tf].value-0)+(box.value-0);
    else
    box.form.elements[tf].value=box.form.elements[tf].defaultValue;
    }
    </script>
    </head>
    <body>
    <form action="#">
    <div>
    <input type="text" name="num" readonly value="1">
    <input type="checkbox" name="bob" value="10" onclick="cbox(this, 'num');">
    </div>
    </form>
    </body>
    </html>
    as a possible avenue toward what you are asking about.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I read "add" as meaning "concatenate." Clarify please, jackavin?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  6. #6
    Join Date
    Jul 2007
    Posts
    59
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    Thank for all post but i want something like hotmail that add contact to CC field when u click on the name it will add more and more and when uncheck that name will out of the textfield something like that

    thank you
    Last edited by jackavin; 09-10-2007 at 05:50 AM.

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Yes, that's what I thought you meant. See my code.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #8
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Well, that certainly sounds like concatenate, as Twey (mind reader that he is :) ) already offered. Does his code work for you or not?

    In any case, have a look at this:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript">
    function cbox(box, tf){
    var dat=box.checked? ' '+box.value : new RegExp(' '+box.value);
    if(box.checked)
    box.form.elements[tf].value+=dat;
    else
    box.form.elements[tf].value=box.form.elements[tf].value.replace(dat, '');
    }
    </script>
    </head>
    <body>
    <form action="#">
    <div>
    <input type="text" name="addys" readonly><br>
    <input type="checkbox" name="bob" value="someone@some.com" onclick="cbox(this, 'addys');"> someone@some.com
    </div>
    </form>
    </body>
    </html>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  9. #9
    Join Date
    Jul 2007
    Posts
    59
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    thank you all without u i will die

  10. #10
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Here's more (from my take on this):

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript">
    function cbox(box, tf){
    var dat=box.checked? ';'+box.value : new RegExp(';\?'+box.value);
    if(box.checked)
    box.form.elements[tf].value+=dat;
    else
    box.form.elements[tf].value=box.form.elements[tf].value.replace(dat, '');
    box.form.elements[tf].value=box.form.elements[tf].value.replace(/^;/, '');
    }
    </script>
    </head>
    <body>
    <form action="#">
    <div>
    <input type="text" name="addys" readonly size="75"><br>
    <input type="checkbox" name="someone0" value="someone0@some.com" onclick="cbox(this, 'addys');"> someone0@some.com<br>
    <input type="checkbox" name="someone1" value="someone1@some.com" onclick="cbox(this, 'addys');"> someone1@some.com<br>
    <input type="checkbox" name="someone2" value="someone2@some.com" onclick="cbox(this, 'addys');"> someone2@some.com<br>
    </div>
    </form>
    </body>
    </html>
    Added Later:

    But, unless this isn't all that critical, none of this will be all that good if there isn't a server side fall back.
    Last edited by jscheuer1; 09-10-2007 at 06:50 AM. Reason: add info
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

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