Solved

Highlight changed form field

Posted on 2014-02-18
9
288 Views
Last Modified: 2014-02-20
Hi

I'm looking for a quick and dirty way to change the style on form fields.

There is no need to remember the old value, so if a change is made and then changed back, the highlight still remains.

Must cover text boxes, radios and dropdowns.

JQuery /  JavaScript.

Andy
0
Comment
Question by:Andy Green
  • 5
  • 3
9 Comments
 
LVL 22

Expert Comment

by:Ivo Stoykov
ID: 39866766
What about:

$(selector).addClass('your_class_name');

Open in new window

HTH
Ivo Stoykov
0
 
LVL 3

Author Comment

by:Andy Green
ID: 39866773
Thanks, I'll give it a try

Andy
0
 
LVL 3

Author Comment

by:Andy Green
ID: 39866788
Re reading my OP and I may have over simplified this.

If a selection is made on a Radio button list then only the selected needs to be highlighted, not any previously selected ones.

Andy
0
 
LVL 7

Expert Comment

by:Kishan Zunjare
ID: 39866875
Through jQuery/HTML/CSS live example of CSS Styling Radio Button/checkbox

http://jsfiddle.net/viralpatel/p499h/

Hope this helps
-Kishan
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 3

Author Comment

by:Andy Green
ID: 39869720
Hi Ivo

Your code doesn't work. I have this working:

               $("input").change(function () {
                  $(this).addClass('highlight');
               });

               $("textarea").change(function () {
                   $(this).addClass('highlight');
               });

But this applies the highlight to every radio button option that is selected, As per my update I only want the selected one to be highlighted.

Also the text box changes colour, but I'd like to expand this to remove the style if the text box is cleared.

Any help would be appreciated

Andy
0
 
LVL 3

Author Comment

by:Andy Green
ID: 39872693
This is a JSFiddle example showing the problem.

http://jsfiddle.net/AndyGreen/QVLZN/3/

Can anyone help?

ANdy
0
 
LVL 7

Accepted Solution

by:
Kishan Zunjare earned 500 total points
ID: 39872827
Hi Andy,

You need to have parent over labels and then you can remove class and add class to selected radio;

Your working solution will be;
jQuery
$('label').click(function(){  
$(this).parents('fieldset').find('label').removeClass('highlight');
$(this).addClass('highlight');
})

Open in new window


HTML
<fieldset>
<label>
    <input id="rdo1" name="rdo1" type="radio" value="1" />
    My Radio 1
    </label>
<br/>
    <label>
    <input id="rdo2" name="rdo1" type="radio" value="1" />
    My Radio 2
    </label>
<br/>
    <label>
    <input id="rdo3" name="rdo1" type="radio" value="1" />
    My Radio 3
    </label>
</fieldset>

Open in new window

0
 
LVL 7

Expert Comment

by:Kishan Zunjare
ID: 39872924
0
 
LVL 3

Author Closing Comment

by:Andy Green
ID: 39876090
Thanks - Just what I needed. I got the textbox bit working.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Form submit issue 11 52
Detecting robots? 5 34
object passed as reference 1 14
JavaScript error 1 33
Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

708 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

13 Experts available now in Live!

Get 1:1 Help Now