Reputation: 5178
Original Question: I'm working towards validation of a user's email with a regular expression after the event of 'focusout' in javascript, but for right now I'm trying to simply get to the point where I can grab the value that was inputted into the field:
code so far:
$(document).on "page:change", ->
$user_email = $('#user_email_form')
$user_email.on 'focusout', ->
alert($user_email.val)
What I want this to do is simply display the text that was entered into an alert box, but instead it is displaying a whole bunch of javascript in the alert box.
Answer
$(document).on "page:change", ->
$(".phone_form").mask("(999) 999-9999")
$(".ssn_form").mask("999-99-9999");
$('#user_email_form').on 'focusout', ->
alert($(@).val())
Upvotes: 0
Views: 673
Reputation: 4171
You need to call val()
as a function as so: $user_email.val()
Also, when you do .on
, you get the target as this, so you can just do this.
$user_email.on 'focusout', ->
val = $(@).val()
Upvotes: 2