0

I'm trying to get the user to enter their email id into the text-box, so I can store it into my database.

Here's the barebones HTML with corresponding jQuery so the code can be examined in its basic functionality. I'm still learning JS so I might have picked up some code from here and there.

Problem: The email id isn't being displayed on screen.

<form id="signup-form">
    <div class="form-group">
        <input type="text" class="form-control" name="email" id="email" placeholder="get informed when it's online!"/>
        <button id="signup-button" class="btn btn-default">count me in!</button>
    </div>
</form>

JQuery:

$("#signup-form").ready(function() {
    $("#signup-button").click(function() {
        alert($('#email').val());
    });
});

Don't know what I'm doing wrong. Help.

2 Answers 2

1

use document

$(document).ready(function() {
    $("#signup-button").click(function() {
        alert($('#email').val());
    });
});
Sign up to request clarification or add additional context in comments.

4 Comments

then you have another mistake in your code. see jsfiddle: jsfiddle.net/jfwxzfug
The .ready method can be used on any element, it's treated as $(document).ready().
@1letter here's the larger code that this snippet is a part of. your jsfiddle code works well, but for some reason it doesnt work when I incorporate the logic to the main code: stackoverflow.com/questions/34810055/…
'#email' + " enrolled in list!" is this really the id of the node?
0

AFAIK, there's no ready jQuery event on form (see list of available jQuery form events). Try handling the button's click event instead:

$("signup-button").on("click", function(e) {
   alert($('#email').val());
});

1 Comment

The ready function can be used with any element, it automatically treats it as $(document).ready().

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.