0

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())

1 Answer 1

2

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()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.