Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

JavaScript Checkbox control HIDE or SHOW Drop-Down List, list of Checkbox controls list of DDL

views
     
TSvearn27
post Apr 15 2010, 05:07 PM, updated 16y ago

Doink! Doink! Doink!
*******
Senior Member
7,284 posts

Joined: Jan 2003
From: Hong Kong / Malaysia




Greetings fellow codemasters from LYN smile.gif

I need a little help here from fellow gurus and would be appreciating any input.

I'm trying to generate a list of checkbox and another list of drop-down list.

By using Javascript, I can control checking the checkbox will show the drop-down list, vice versa unchecking it will hide the drop-down list. But, so far I only managed to achieve if 1 checkbox VS 1 drop-down list.

How can I actually achieve this for a list of dynamic generated checkbox and drop-down box through loop?

I think there is a way to do it would be passing the ID of the checkbox to the javascript function and then will disable the drop-down box controlled by that ID, but still no luck in getting the actual working code.

Anyone could please share and help me here? Deeply appreciate your effort. Thank you smile.gif

P/S: Enable and Disable will work as well. I'm generating the page with PHP and adding in javascript function.
exentric_nova
post Apr 15 2010, 10:15 PM

I Am Serious
******
Senior Member
1,702 posts

Joined: Jan 2003
From: Semenyih


I have done this before and it really was quite easy. Yes, you will be needing the ID of the drop down list.

My method is inserting that ID within the checkbox value. Once the checkbox is checked/unchecked, my script will capture the value of said checkbox, and toggle view according to the ID captured.

Different checkbox will have different value hence toggling different drop down list.

I can give an example of code, but are you using any framework or just plain Javascript? Since I'm only capable of doing JS using JQuery sweat.gif
TSvearn27
post Apr 15 2010, 10:39 PM

Doink! Doink! Doink!
*******
Senior Member
7,284 posts

Joined: Jan 2003
From: Hong Kong / Malaysia




I'm just on plain HTML, PHP and Javascript smile.gif

Yes, please do share with me your example of code. I would deeply appreciate it.
exentric_nova
post Apr 15 2010, 10:44 PM

I Am Serious
******
Senior Member
1,702 posts

Joined: Jan 2003
From: Semenyih


Well if you don't mind JQuery, here it is. sweat.gif

CODE

$('input:checkbox').click(function() {
 var target = $(this).val();
 if(this.checked == true) {
  $('#'+target).show();
 }
 if(this.checked == false) {
  $('#'+target).hide();
 }
});


This post has been edited by exentric_nova: Apr 15 2010, 10:46 PM
slier81
post Apr 15 2010, 10:54 PM

On my way
****
Senior Member
541 posts

Joined: Jun 2007
From: Penang
show us ur code...then we can suggest
p/s:my advice learn the language itself before to use any of the framewrok
by the way in ur case u just need:

document.createElement,
document.createTextNode,
document.getElemenById,
elem.setAtrribute,
elem.getAttribue
document.appendCHild

pure Dom manipulation

 

Change to:
| Lo-Fi Version
0.0152sec    1.49    5 queries    GZIP Disabled
Time is now: 27th November 2025 - 05:33 AM