Click to See Complete Forum and Search --> : resetting checkboxes and radios


gogotina
10-22-2003, 01:56 PM
Is it posiable to nove th value for the "item_name" text box to the"result1" text box and reseting the checkboxes and radio 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.

Jona
10-22-2003, 02:00 PM
document.forms["form_name"].name_of_element.value = document.forms["first_form_name"].name_of_first_form_element.value;


[J]ona

gogotina
10-22-2003, 02:14 PM
sorry the code did not go.......

Jona
10-22-2003, 02:29 PM
<input type="button" value="move total below" onclick="KeepCount(this.form)"><br>


[J]ona

gogotina
10-22-2003, 02:56 PM
I still and not get the code to go..
lets tru this

<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>

Jona
10-22-2003, 03:13 PM
Is this what you want?


<script language="javascript">
function keepCount(f) {
var checked = 0, maxnum = 5, i, Coma=',';
f.item_1.value = '';
f.item_2.value = '';
f.item_name.value = '';
for(i=0;i<f.elements.length;i++){
if(f.elements[i].type == 'checkbox' && f.elements[i].checked){
if(checked < maxnum){
f.item_1.value += f.elements[i].value;
checked++;
}
else{
alert('You are only allowed to pick ' + maxnum + ' items');
f.item_name.value += f.item_1.value;
return false;
}
}
if(f.elements[i].type == 'radio' && f.elements[i].checked){
f.item_2.value += f.elements[i].value;
}
}

if(f.item_name.value != ""){
f.item_name.value += ","+f.item_1.value;
} else {
f.item_name.value += f.item_1.value;
}
f.item_name.value += f.item_2.value;
return true;
}
function moveData(f){
f.result1.value = f.item_1.value;
f.result2.value = f.item_2.value;
f.result3.value = f.item_name.value;
}
</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" onclick="moveData(this.form)"><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>


[J]ona

gogotina
10-22-2003, 03:37 PM
not quite. I would like the move total below button to move the value of"item_name" to "result1" then clear/rest the values for item_1, item_2, item_name so it can be done again for "result2". I guess that I am trying to loop through the checkboxes and radios 3 times and displaying the information collected in "result1", "result2","result3"

Jona
10-22-2003, 03:42 PM
Replace the above moveData() function with this one:


function moveData(f){
if(f.result1.value=="result1")
{f.result1.value = f.item_name.value;}
if(f.result2.value=="result2" && f.result1.value != "result1")
{f.result2.value = f.item_name.value;}
if(f.result3.value=="result3" && f.result2.value != "result2")
{f.result3.value = f.item_name.value;}
}


Edited the code.

[J]ona

Jona
10-22-2003, 03:57 PM
Okay, scratch again... Try this...


function moveData(f){
if(f.result3.value=="result3" && f.result2.value != "result2")
{f.result3.value = f.item_name.value;}
if(f.result2.value=="result2" && f.result1.value != "result1")
{f.result2.value = f.item_name.value;}
if(f.result1.value=="result1")
{f.result1.value = f.item_name.value;}
}


[J]ona

gogotina
10-22-2003, 04:05 PM
well... the "move total below" button moves the info into all tree "result" text boxes and it dose not reset the checkboxes and radios to unchecked status. ???

Jona
10-22-2003, 04:09 PM
function moveData(f){
if(f.item_name.value != "total"){
if(f.result3.value=="result3" && f.result2.value != "result2")
{f.result3.value = f.item_name.value;}
if(f.result2.value=="result2" && f.result1.value != "result1")
{f.result2.value = f.item_name.value;}
if(f.result1.value=="result1")
{f.result1.value = f.item_name.value;}
} }


[J]ona

gogotina
10-22-2003, 04:19 PM
close.. it still dose not clear the checkboxes or radios.

Jona
10-22-2003, 04:23 PM
Originally posted by gogotina
close.. it still dose not clear the checkboxes or radios.

Didn't remember that part...


function moveData(f){
if(f.item_name.value != "total"){
if(f.result3.value=="result3" && f.result2.value != "result2")
{f.result3.value = f.item_name.value;}
if(f.result2.value=="result2" && f.result1.value != "result1")
{f.result2.value = f.item_name.value;}
if(f.result1.value=="result1")
{f.result1.value = f.item_name.value;}
}
for(m=0; m<f.elements.length; m++){
if(f.elements[m].type == "checkbox" || f.elements[m].type == "radio" && f.elements[m].checked){
f.elements[m].checked=false;
} }
}


[J]ona

gogotina
10-22-2003, 04:32 PM
GREAT... but it dose not reset the checkboxes and radios until one of them is clicked and we losted the camas between the checkbox totals and the radio.

Jona
10-22-2003, 04:40 PM
Originally posted by gogotina
GREAT... but it dose not reset the checkboxes and radios until one of them is clicked and we losted the camas between the checkbox totals and the radio.


function keepCount(f) {
var checked = 0, maxnum = 5, i, Coma=',';
f.item_1.value = '';
f.item_2.value = '';
f.item_name.value = '';
for(i=0;i<f.elements.length;i++){
if(f.elements[i].type == 'checkbox' && f.elements[i].checked){
if(checked < maxnum){
f.item_1.value += f.elements[i].value;
checked++;
}
else{
alert('You are only allowed to pick ' + maxnum + ' items');
f.item_name.value += f.item_1.value;
return false;
}
}
if(f.elements[i].type == 'radio' && f.elements[i].checked){
f.item_2.value += f.elements[i].value;
}
}

f.item_name.value += f.item_1.value+",";

f.item_name.value += f.item_2.value;
return true;
}


[J]ona

gogotina
10-22-2003, 04:48 PM
still dose not reset the checkboxes and radio until one of the are clicked. Can they be reset with the "onclick" of the"move total below" button?

Jona
10-22-2003, 04:50 PM
Originally posted by gogotina
still dose not reset the checkboxes and radio until one of the are clicked. Can they be reset with the "onclick" of the"move total below" button?

I do not understand that...

[J]ona

gogotina
10-22-2003, 04:55 PM
I'm sorry. The checkboxes and radios are being reset. The values for f.item_1, f.item_2, and item_name are what I was looking at. Can we reset them too?

Jona
10-22-2003, 04:57 PM
function moveData(f){
if(f.item_name.value != "total"){
if(f.result3.value=="result3" && f.result2.value != "result2")
{f.result3.value = f.item_name.value;}
if(f.result2.value=="result2" && f.result1.value != "result1")
{f.result2.value = f.item_name.value;}
if(f.result1.value=="result1")
{f.result1.value = f.item_name.value;}
}
for(m=0; m<f.elements.length; m++){
if(f.elements[m].type == "checkbox" || f.elements[m].type == "radio" && f.elements[m].checked){
f.elements[m].checked=false;
} }
f.item_1.value="";
f.item_2.value="";
f.item_name.value="";
}


[J]ona

gogotina
10-22-2003, 05:03 PM
:D :D :D THNXXXX :D :D :D

Jona
10-22-2003, 05:04 PM
You're welcome.

[J]ona