Applying and changing the classname of selected radio with scripting

Posted on 2011-10-07
Last Modified: 2012-08-13

I have a form that has a radio button set.  When the page loads, I want use some simple scripting that immediately apply a classname to the label of the corresponding input and when the user click on another radio button in the set to remove that class and apply the classname to the newly selected radio button label.

Any ideas how this can be done?



<form id="myForm" action="" method="post">
   <input type="radio" id="radio1" name="myRadio" value="radio1">
   <label for="radio1">radio1</label>
   <input type="radio" id="radio2" name="myRadio" value="radio2">
   <label for="radio2">radio2</label>
   <input type="radio" id="radio3" name="myRadio" value="radio3" checked="checked">
   <label for="radio3">radio3</label>
   <input type="radio" id="radio4" name="myRadio" value="radio4">
   <label for="radio4">radio4</label>

Open in new window

Question by:JaXL
    1 Comment
    LVL 40

    Accepted Solution


    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
    Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
    The viewer will learn how to count occurrences of each item in an array.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now