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

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Java hidden & visible form elements

Reply to Message Icon

Name: Skewkus
Date: June 21, 2006 at 01:46:18 Pacific
OS: XP
CPU/Ram: 2Gig
Product: 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.



Sponsored Link
Ads by Google

Response Number 1
Name: Michael J (by mjdamato)
Date: June 21, 2006 at 08:26:21 Pacific
Reply:

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


0

Response Number 2
Name: Skewkus
Date: June 21, 2006 at 14:07:22 Pacific
Reply:

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.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: Java hidden & visible form elements

forms code included www.computing.net/answers/webdevel/forms-code-included/1510.html

Creating javascript arrays in forms www.computing.net/answers/webdevel/creating-javascript-arrays-in-forms/1435.html

parsing sequence of DHTML-form www.computing.net/answers/webdevel/parsing-sequence-of-dhtmlform/2209.html