on selecting this radio button, set the class of this div to this

This is a discussion on "on selecting this radio button, set the class of this div to this" within the JavaScript Forum section. This forum, and the thread "on selecting this radio button, set the class of this div to this are both part of the Program Your Website category.



 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Reply
 
LinkBack Thread Tools
  #1  
Old Dec 13th, 2007, 07:34
Up'n'Coming Member
Join Date: May 2007
Location: northern nsw, au
Age: 27
Posts: 76
Thanks: 0
Thanked 0 Times in 0 Posts
on selecting this radio button, set the class of this div to this

hello masters of the js universe, I need some assistance.

I have 3 or so radio inputs and upon clicking them I'd like an enclosing div tag to have a css class applied to it. Then, upon clicking one of the other radio inputs I'd like the class on the previously selected input to be deactivated.

The form I'm referring to with this is at http://triumphantevents.co.uk/events...=djd-bt_busrel


With the enclosing div tag, is the concept to give it an id? and then on the radio button something like:
Code: Select all
onclick="document.getElementById('divID').class='formsel';"
Doesn't seem to work for me. But what I'm really curious about is the way to deselect the div's class that has the class 'formsel' applied once another radio button has been checked... e.g to do it, do I need to create an individual function to de-formsel each div? or is there a way to just say "if this radio button is selected, apply this class to every other div besides this one"?


Thanks for any help on this.

Last edited by cosmicbdog; Dec 13th, 2007 at 07:40. Reason: more info to help the cause
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Dec 13th, 2007, 07:41
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: on selecting this radio button, set the class of this div to this

Okay, this is a fairly simple task

what you want is to set up a function somewhere

Code: Select all
function changeClass(divToChange, newClass)
{
        divToChange = document.getElementById(divToChange);
        divToChange.className = newClass;
}
now of course you already have a stylesheet and know what class you want to use for each radio button. Give the div you want to change an id="this" element supplementing "this" with what you like in the below code

Code: Select all
<input type="radio" value="something" name="somethingelse" onclick="this.checked ? changeClass('this', 'className') : ''" />
<input type="radio" value="somethingthatsnotnothing" name="something" onclick="this.checked ? onclick('this', 'className2')" />
etc...

Fairly simple example above but it should perform the task
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Dec 20th, 2007, 00:14
Up'n'Coming Member
Join Date: May 2007
Location: northern nsw, au
Age: 27
Posts: 76
Thanks: 0
Thanked 0 Times in 0 Posts
Re: on selecting this radio button, set the class of this div to this

I have been studying this post for a week, honestly. It is gradually making sense to me.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Dec 20th, 2007, 05:53
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: on selecting this radio button, set the class of this div to this

LOL, sorry, I normally comment my examples...

The function takes two arguments, the id of a HTML element and the name of the class that this element will receive.

Within the function, the first line is storing a reference to the html element with the next line setting the className property to the given class.

The HTML code contains a ternary function call esentially, when the radio button is clicked, it checks whether that click has resulted in the radio button being selected. If it has, it runs the function giving it an element id and a class name. If it turns out that this click has resulted in the radio not being checked any longer, nothing happens.

Hope that makes it a bit clearer.
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Selected radio button value Pugger JavaScript Forum 8 Nov 3rd, 2007 12:16
radio button interfering with drop down antonyx JavaScript Forum 1 Apr 27th, 2007 00:11
Any way to use an image for a radio button? masonbarge Web Page Design 23 Jan 6th, 2007 09:06
automatic pop-up when click on a radio button joshcxa JavaScript Forum 2 Aug 1st, 2006 06:06
Help Please - Radio Button Labels not showing sandyb Flash & Multimedia Forum 0 Jan 16th, 2006 22:56


All times are GMT. The time now is 19:24.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42