Add event to input field using class name.

Hello,

I have an input field which i can add an blur event using :

$( "#H_ogo_OperationTyp1" ).on( "blur", function() {
  alert("hejosdfjlskjflsj") ;
});

Open in new window


But if want to add it to 6 fields, and these fields have a class called "opTYP".

what would the syntax be to add it to all fields of class "opTYPE"?

Thanks!
soozhCEOAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dorababu MSenior Software EngineerCommented:
Can you show me your html design and what is your expected output on blur event.
A sample fiddle http://jsfiddle.net/BZRLG/5/
0
soozhCEOAuthor Commented:
Thanks for the input.

The blur event will convert the chartacters to upper case.

I thought the general syntax would be

$(".opTYPE").each(function() { etc...

and that would add the blur event to each field with the class "opTYPE"
0
Dorababu MSenior Software EngineerCommented:
If your form is having all input type as text then you can try this way
$(document).on('blur', "input[type=text]", function () {
    $(this).val(function (_, val) {
        return val.toUpperCase();
    });
});

Open in new window


Fiddle on the same http://jsfiddle.net/BZRLG/193/
0
Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

soozhCEOAuthor Commented:
unfortunately on some of the inputs are like this.  those with the class opTYPE.
0
Dorababu MSenior Software EngineerCommented:
Try this and let me know
$(document).ready(function () {
    $('.form-control').bind('blur', function () {
        $(this).val(function (_, val) {
        return val.toUpperCase();
    });
})
});

Open in new window

0
soozhCEOAuthor Commented:
i cant see how that will work.

I have many input fields on my form (30+) and only on six of them i want to add the onblur event to convert the contents to uppercase.

So i have given these six a class called opTYPE because i though i could write some jquery that added the neccessary code to just those six fields.

Not possible?
0
Chris StanyonWebDevCommented:
You just need to add the blur event to the class selector:

$(".opTYPE").on( "blur", function() {
    console.log( $(this).val() );
});

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dorababu MSenior Software EngineerCommented:
If you can post your html I can look in to
0
Dorababu MSenior Software EngineerCommented:
How it is different from mine you just need to change the class .form-control to .opTYPE
0
soozhCEOAuthor Commented:
well with my limited knowledge of jQuery i did not understand to change .form-control to .opTYPE
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.