Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Sorry for posting again so soon however I am still stuck.
Below is a sample code of what I am trying to do:
<script>
function enableDisable0()
{
if(document.myform.tickbox1.checked == true)
{
var objects = document.getElementsByTagName("input");
for(var no=0;no<objects.length;no++)
{
objects[no].style.visibility = "visible";
}
}</script>
<HTML>
<form method="POST" name="myform" action="">
<input name="Option1" type="checkbox" size="20" style="visibility: hidden;" />
<input name="Option2" type="checkbox" size="20" style="visibility: hidden;" />
<input name="Option3" type="checkbox" size="20" style="visibility: hidden;" />Click this tick box to make others appear.
<input type="checkbox" name="tickbox1" value="ON" onclick="enableDisable0()"></form>
</HTML>
What I want to happen is when someone clicks tickbox1 I want option1 option2 and option3 to appear,
Little run down on my situation.
I have a photo gallery written in PHP, what happens is when someone opens one of the gallerys, a php "while loop" is called which grabs all the photos in the users directory and outputs them as thumbnails. Each thumbnail also has a tickbox next to it (Option1, Option2, Option3) the tickbox is used so people can tick 1 or more photos then press delete to remove them, however I don't want the tick boxes to appear next to the thumbnails unless they first click a "Click to display delete options" tickbox first.
You can see from that, that I can not use the
getElementById
or
getElementByNameas every photos checkbox will have its own unique name and id, so I wanted to use the
getElementsByTagName (input)
Many thanks for anyone who can see why my script doesn't work.

Your script worked for me after I added a closing curly bracket at the end of the function!
Assuming you will have a form for each image on the page, you need your function to be able to work with any of them (i.e. you should not hard code the form name in the function). Try this code. I think it is a little more flexible.
<HTML>
<head>
<script>
function enableDisable0(checkBox) {if(checkBox.checked == true) {
visStyle = "visible";
} else {
visStyle = "hidden";
}form = checkBox.form;
form.Option1.style.visibility = visStyle;
form.Option2.style.visibility = visStyle;
form.Option3.style.visibility = visStyle;
form.Option1.checked = false;
form.Option2.checked = false;
form.Option3.checked = false;
}</script>
</head><form method="POST" name="myform" action="">
<input name="Option1" type="checkbox" size="20" style="visibility: hidden;" />
<input name="Option2" type="checkbox" size="20" style="visibility: hidden;" />
<input name="Option3" type="checkbox" size="20" style="visibility: hidden;" />Click this tick box to make others appear.
<input type="checkbox" name="tickbox1" value="ON" onclick="enableDisable0(this)"></form>
</HTML>
Michael J

Wow ok I spent hours trying to get that working last night, ans all it was is the curly bracket, man I must have been tired - perhaps I needed more coffee,
..oh and no im not using a form for each image as I only want the one submit button
I like your script also, I may actually end up using that thanks.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |