Computing.Net > Forums > Web Development > Java hidden & visible form elements

Java hidden & visible form elements

Reply to Message Icon

Original Message
Name: Skewkus
Date: June 21, 2006 at 01:46:18 Pacific
Subject: Java hidden & visible form elements
OS: XP
CPU/Ram: 2Gig
Model/Manufacturer: Athlon
Comment:

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
getElementByName

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


Report Offensive Message For Removal

Response Number 1
Name: Michael J (by mjdamato)
Date: June 21, 2006 at 08:26:21 Pacific
Subject: Java hidden & visible form elements
Reply: (edit)

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


Report Offensive Follow Up For Removal

Response Number 2
Name: Skewkus
Date: June 21, 2006 at 14:07:22 Pacific
Subject: Java hidden & visible form elements
Reply: (edit)

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.


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Java hidden & visible form elements

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software