You are viewing limited content. For full access, please sign in.

Question

Question

Blur Event For Drop Down Box

asked on July 31, 2014

How do I target a drop down box in js to have a blur function occur?

0 0

Answer

SELECTED ANSWER
replied on July 31, 2014

so not within a collection either?

 

instead of '.age' try '#Field' and put the field number before the single quotation mark.

1 0

Replies

replied on July 31, 2014 Show version history

Should be:

$(".target").blur(function(){
    alert("value changed");
});

That's from the sample functions provided inside of the forms Javascript area. You need to assign the dropdown a css class, and then it should probably be: '.targetCSSclass input' instead of just the target CSS class

0 0
replied on July 31, 2014

I tried that and the alert doesnt trigger. How would I return the value of the drop down. I think I might have to alert based on the value.

0 0
replied on July 31, 2014 Show version history

is that within a 

 

$(document).ready(function() {

....
....
});

section?

 

EDIT: may also want to try single quotation instead of double quotation for the css class part and the alert part. 

0 0
replied on July 31, 2014

Yes, everything is inside the ready function. I dont normally use double quotes int he selectors but I've tried both ways already. 

 

 

Heres the code

 

function get_question () {
    
    var user_age = $('.age').val() ;
    alert ( user_age ) ;

}

 

0 0
replied on July 31, 2014

And the blur function still isnt working either. I was going to have a variable that would hold the age whenever the age drop down was blurred. But I cant get it to blur!

0 0
replied on July 31, 2014

use '.age input' instead of '.age'

 

Let me know what happens

0 0
replied on July 31, 2014

Still no alert on the blur function and the one I posted

0 0
replied on July 31, 2014

can you try the alert before the var declaration? just have the alert output any text you want. We need to ensure that the function is even being run before we try troubleshooting it's contents.

0 0
replied on July 31, 2014

Okay, its running but the value it puts for $( ' .age input ' ).val() is undefined.

I have values assigned to the different options.

0 0
replied on July 31, 2014

okay, so the dropdown is just that, a dropdown, not in a table or anything, is it?

0 0
replied on July 31, 2014

Nope, just a single drop down with 3 choices.

0 0
SELECTED ANSWER
replied on July 31, 2014

so not within a collection either?

 

instead of '.age' try '#Field' and put the field number before the single quotation mark.

1 0
replied on July 31, 2014

Boom.. thats what we needed. I wonder why the field target would work but not the class or id?

0 0
replied on July 31, 2014

Sometimes that just is how it is, but between '#Field1' and '.field1 input' I always seem to get it to work. 

 

Things do get trickier to reference when inside collections or tables.

0 0
replied on July 31, 2014

Yeah, I tried using those but just avoided it because this way is much simpler and easy to understand! Thank you for the help.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.