How do I target a drop down box in js to have a blur function occur?
Question
Question
Answer
so not within a collection either?
instead of '.age' try '#Field' and put the field number before the single quotation mark.
Replies
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
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.
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.
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 ) ; }
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!
use '.age input' instead of '.age'
Let me know what happens
Still no alert on the blur function and the one I posted
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.
Okay, its running but the value it puts for $( ' .age input ' ).val() is undefined.
I have values assigned to the different options.
okay, so the dropdown is just that, a dropdown, not in a table or anything, is it?
Nope, just a single drop down with 3 choices.
so not within a collection either?
instead of '.age' try '#Field' and put the field number before the single quotation mark.
Boom.. thats what we needed. I wonder why the field target would work but not the class or id?
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.
Yeah, I tried using those but just avoided it because this way is much simpler and easy to understand! Thank you for the help.