Solved

Highlight changed form field

Posted on 2014-02-18
9
295 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
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Html Table looping 4 26
jquery tab header text 1 23
how to use .length with "input" 2 25
ASP.NET MVC -Update model when click on <li> element 29 35
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…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

831 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