Click to See Complete Forum and Search --> : checkbox-to-list
W8 4me
06-11-2003, 12:42 PM
[checkbox] Beans
[checkbox] Carrots
[checkbox] Potatoes
[checkbox] Sweet Corn
[checkbox] Rice
[button] [reset button]
[textarea]
What I would like my users to be able to do is make a custom list by ticking all/some of the checkboxes, and then pressing the button to create the list in the textarea. The [button] must also copy the list to the clipboard. Any help is appreciated. :)
Does it have to be in order?
Jona
I made this (http://geocities.com/god_loves_07/appendList.html) script for ya, but it doesn't automatically copy the text to clipboard (didn't wanna do that :p).
Jona
W8 4me
06-11-2003, 02:55 PM
Thanks, that'll do nicely. :)
I take it I can add loads more checkboxes without having to change the script?
Yes, if you update your array. Here is an updated version of the script which you will not need to update (note: untested code):
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html><head><title>Append List</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
input {background-color:#a9a;}
body {background-color:#a9a;}
textarea {background-color:#a9a;}
-->
</style>
<script type="text/javascript">
<!--
function appendList(f){
f.t.value="";
var chkd=new Array();
for(i=0;i<f.elements.length;i++){
if(f.elements[i].type=="checkbox"){chkd[i]=f.elements[i];}
}
for(i=0;i<chkd.length;i++){
chkd[i].value=chkd[i].name;
if(chkd[i].checked){
f.t.value+=chkd[i].value+"\n";}
}
}
//-->
</script></head><body>
<form name="myform"><div>
<input type="checkbox" name="a">A<br>
<input type="checkbox" name="b">B<br>
<input type="checkbox" name="c">C<br>
<input type="checkbox" name="d">D<br><br>
<textarea name="t" rows="10" cols="15"></textarea>
<br><input type="button" onClick="appendList(this.form);" value="Append to list">
</div></form></body></html>
Jona
SearedIce
06-11-2003, 03:10 PM
you would have to change this line:
var chkd = new Array(f.a, f.b, f.c, f.d);
lets say you add two checkboxes, one named 2 and the other 3
then that line will look like
var chkd = new Array(f.a, f.b, f.c, f.d, f.2, f.3);
i'd like to make a version of your script that would make it so you don't have to change anything, and i'm 100% sure i could but i don't know enough about the built-in form arrays to make it find how many checkboxes are already there...sorry
~John
SearedIce
06-11-2003, 03:26 PM
jona,
document.myform.length returns the number of things in the form
minus two and you have the number of checkboxes (in this case)...lets say we stored this number in a variable called numofcheckboxes
thus document.myform[0] through document.myform[numofcheckboxes-1] will be the checkboxes
i'm not sure if this helps, but it should.....i'm talking about helping when making a script where any number of checkboxes can exist
~John
W8 4me
06-11-2003, 03:29 PM
Let's say I wanted to have the list of checkboxes in an iframe and the textarea would be on the parent page. Is there a way to append the list to the textarea on the parent page from an iframe?
Yes, there is. Hold on a second, and I will update the script for you.
SearedIce, document.myform.elements.length does return the number of elements in the form, however, I used a for() loop to go through all of them and return each one individually, so that f.elements[i] is the object in the DOM.
Jona
Refer back to the link (http://www.geocities.com/god_loves_07/appendList.html) I gave you. I have updated the script, and you do not need to change it at all.
Jona
W8 4me
06-11-2003, 04:49 PM
Thanks but I actually meant this......
Parent html page -----------
[textarea] [iframe]
Iframe html page ----------
[checkbox] Beans
[checkbox] Carrots
[checkbox] Potatoes
[checkbox] Sweet Corn
[checkbox] Rice
[button]
--------------
I have very long lists so I want to put them in the iframe, but have the final list easily accessible (to the left of the iframe on the parent page).
LOL, okay. Let me set up another page for that. :rolleyes: Be back in a few minutes with a new script.
Jona
OK, tell me if this here (http://geocities.com/god_loves_07/outerListFrame.html) works for you.
Jona
W8 4me
06-11-2003, 09:44 PM
Sorry but that's not what I meant either! This may explain it better........
www.aldokimc.34sp.com/helpme.jpg
That image doesn't show up. Upload it to this forum so I can view it.
Edit: The image now shows up; it didn't last night. Let me make yet another set of pages for this "new" script... :p LOL
Jona
OK, now tell me what you think of this (http://www.geocities.com/god_loves_07/olfr.html) one! :p
Jona
W8 4me
06-12-2003, 12:19 PM
Wooohoooooooooo! Sorry for being awkward! :)