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 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Apr 2003
    Location
    upper midwest
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    resetting checkboxes and radios

    Is it posiable to move the value for the "item_name" text box to the"result1" text box and resetting the checkboxes and radios for the next set of information? I want to be able to do this for "result1","result2","result3"
    text boxes using the "move total below" button.
    <script language="javascript">
    function KeepCount(form)
    {
    var checked = 0;
    var maxnum = 5;
    var i;
    var Coma=',';
    form.item_1.value = '';
    form.item_2.value = '';
    form.item_name.value = '';
    for(i=0;i<form.length;i++)
    {
    if(form.elements[i].type == 'checkbox' && form.elements[i].checked)
    {
    if(checked < maxnum)
    {
    form.item_1.value += form.elements[i].value;
    checked++;
    }
    else
    {
    alert('You are only allowed to pick ' + maxnum + ' items');
    form.item_name.value += form.item_1.value ;
    return false;
    }
    }
    if(form.elements[i].type == 'radio' && form.elements[i].checked)
    {
    form.item_2.value += form.elements[i].value ;
    }
    }
    form.item_name.value += form.item_1.value ;
    form.item_name.value += Coma ;
    form.item_name.value += form.item_2.value ;
    return true;
    }
    </script>
    <form name="item1"><input type="text" name="item_1" value="checkboxes"><input type="text" name="item_2" value="radios"><input type="text" name="item_name" value="total"><small><br>
    <input type="checkbox" value="01" onclick="return KeepCount(this.form)"></small><small> 1&nbsp;</small><small><input type="checkbox" value="02" onclick="return KeepCount(this.form)"></small><small>
    2&nbsp; </small><small><input type="checkbox" value="03" onclick="return KeepCount(this.form)"></small><small>
    3&nbsp;</small><small><input type="checkbox" value="04" onclick="return KeepCount(this.form)"></small><small>
    4&nbsp; </small><small><input type="checkbox" value="05" onclick="return KeepCount(this.form)"></small><small>
    5&nbsp;</small><small><input type="checkbox" value="06" onclick="return KeepCount(this.form)"></small><small>
    6&nbsp; </small><small><input type="checkbox" value="07" onclick="return KeepCount(this.form)"></small><small>
    7&nbsp;</small><small><input type="checkbox" value="08" onclick="return KeepCount(this.form)"></small><small>
    8&nbsp; </small><small><input type="checkbox" value="09" onclick="return KeepCount(this.form)"></small><small>
    9&nbsp;</small><small><input type="checkbox" value="10" onclick="return KeepCount(this.form)"></small><small>
    10&nbsp; </small><small><input type="checkbox" value="11" onclick="return KeepCount(this.form)"></small><small>
    11&nbsp;</small><small><input type="checkbox" value="12" onclick="return KeepCount(this.form)"></small><small>
    12&nbsp; </small><small><input type="checkbox" value="13" onclick="return KeepCount(this.form)"></small><small>
    13&nbsp;</small><small><input type="checkbox" value="14" onclick="return KeepCount(this.form)"></small><small>
    14&nbsp; </small><small><input type="checkbox" value="15" onclick="return KeepCount(this.form)"></small><small>
    15&nbsp;</small><small><input type="checkbox" value="16" onclick="return KeepCount(this.form)"></small><small>
    16&nbsp; </small><small><input type="checkbox" value="17" onclick="return KeepCount(this.form)"></small><small>
    17&nbsp;</small><small><input type="checkbox" value="18" onclick="return KeepCount(this.form)"></small><small>
    18&nbsp; </small><small><input type="checkbox" value="19" onclick="return KeepCount(this.form)"></small><small>
    19&nbsp;</small><small><input type="checkbox" value="20" onclick="return KeepCount(this.form)"></small>
    20&nbsp; <small><br>
    </small><br>
    <small><input type="radio" name="item2" value="1" onclick="return KeepCount(this.form)"></small><small>
    1&nbsp;</small><small><input type="radio" name="item2" value="2" onclick="return KeepCount(this.form)"></small><small>
    2&nbsp; </small><small><input type="radio" name="item2" value="3" onclick="return KeepCount(this.form)"></small><small>
    3&nbsp;</small><small><input type="radio" name="item2" value="4" onclick="return KeepCount(this.form)"></small><small>
    4&nbsp; </small><small><input type="radio" name="item2" value="5" onclick="return KeepCount(this.form)"></small><small>
    5&nbsp;</small><small><input type="radio" name="item2" value="6" onclick="return KeepCount(this.form)"></small><small>
    6&nbsp; </small><small><input type="radio" name="item2" value="7" onclick="return KeepCount(this.form)"></small><small>
    7&nbsp;</small><small><input type="radio" name="item2" value="8" onclick="return KeepCount(this.form)"></small><small>
    8&nbsp; </small><small><input type="radio" name="item2" value="9" onclick="return KeepCount(this.form)"></small><small>
    9&nbsp;</small><small><input type="radio" name="item2" value="10" onclick="return KeepCount(this.form)"></small><small>
    10 </small><br>
    <input type="button" value="move total below"><br>
    <input type="text" name="result1" value="result1"><input type="text" name="result2" value="result2"><input type="text" name="result3" value="result3"></form>

    </body>
    </html>
    Last edited by gogotina; 10-22-2003 at 09:09 PM.

  • #2
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Place this script in the <HEAD>

    <script type="text/javascript">
    function moveTotal() {
    var f1=document.item1;

    f1.result1.value = f1.item_1.value;
    f1.result2.value = f1.item_2.value;
    f1.result3.value = f1.item_name.value;

    }
    </script>

    Add the onClick event handler to your button

    <input type="button" value="move total below" onClick="moveTotal()">

    .....Willy

    Ooops;
    Just reread your post and you also wanted to reset
    the elements. I'll have to get back to you. :0
    Last edited by Willy Duitt; 10-22-2003 at 09:15 PM.

  • #3
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry about that.
    Try this:

    <script type="text/javascript">
    function moveTotal() {
    var f1=document.item1;

    f1.result1.value = f1.item_1.value;
    f1.result2.value = f1.item_2.value;
    f1.result3.value = f1.item_name.value;
    clearForm();
    }

    function clearForm() {
    var f1=document.item1;
    var f2=document.item1.length;
    for (var i=0;i<f2;i++) {
    f1.elements[i].checked=0;
    }
    f1.item_1.value = "";
    f1.item_2.value = "";
    f1.item_name.value = "";
    }
    </script>

    <input type="button" value="move total below" onClick="moveTotal()">

    ....Willy

  • #4
    New to the CF scene
    Join Date
    Apr 2003
    Location
    upper midwest
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    can we make it so that "move total below" moves only the value from item_name to "result1", the second time send the value from item_name to "result2", then the third time send the value from item_name to "result1". Like looping through the checkboxes and radios tree times and keeping the results in the "result1", "result2", and result3" textboxes.

  • #5
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Is this for a class project or a real time application?


    .....Willy

  • #6
    New to the CF scene
    Join Date
    Apr 2003
    Location
    upper midwest
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    sorry this is taking so much of your time. it is just for a game with my 6year old boy.

  • #7
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    No need to apologize.
    I wouldn't be helping if I didn't want to.
    Besides, this is how I learned javascript (still learning)

    I was just wondering about the class project.
    But a game for your 6 year old.....

    Here try this:

    function MakeArray(n) {
    if(n<=0)
    {
    this.length = 0;
    return this;
    }
    this.length = n;
    for( var i=1; i<=n; i++)
    {
    this[i] = 0;
    }
    return this;
    }
    var item1 = new MakeArray(3);
    var index = 0;

    function store(str) {
    var i;
    if(index>=item1.length)
    {
    for( i=1; i<item1.length; i++)
    item1[i-1] = item1[i];
    index = item1.length-1;
    }
    item1[index] = str;
    ++index;
    }
    function moveTotal() {
    var f1=document.item1;
    f1.result1.value=item1[0];
    f1.result2.value=item1[1];
    f1.result3.value=item1[2];
    {
    clearForm();
    }
    }

    function clearForm() {
    var f1=document.item1;
    var f2=f1.length;
    for (var i=0;i<f2;i++) {
    f1.elements[i].checked=0;
    }
    f1.item_1.value="";
    f1.item_2.value="";
    f1.item_name.value="";
    }

    Post back if you have any more questions.
    Glad to help;
    .....Willy

    Ooops;
    Edited: 10/23/2003 1:35 EST
    Made a change and I think I broke it.
    Replaced code and attached a working copy here.
    Last edited by Willy Duitt; 10-23-2003 at 06:37 PM.


  •  

    Posting Permissions

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