Solved

Highlight changed form field

Posted on 2014-02-18
9
303 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

 
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
 
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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

724 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