Hello,

I am trying to write email confirmation with javascript:

     <div class="step">
                <h4>Enter your email address:</h4>

                    <div class="container">
                        <input type="text" name="email" value="Enter your email here" title="Enter your email here" class="field" />
                    </div>
                    <h5>Step 2 of 2</h5>
                    <span class="progress"><span style="width: 100%">&nbsp;</span></span>
                    <input class="email-btn button" type="submit" value="Send" />
                </form>
            </div>

            ...

            $('.email').click(function() {

    var email = $(this).parent().find('email').val();

    if (email == null) {
        alert('Please enter your email address.');
    }

    return false;
};

How to write the javascript?

Recommended Answers

All 2 Replies

Member Avatar for diafol

You have a trigger for clicking on a tag with class of 'email'. But this class does not exist in your markup.

I change the codes to:

 <div class="step">
                <h4>Enter your email address:</h4>

                    <div class="container">
                        <input type="text" id="email" name="email" value="Enter your email here" title="Enter your email here" class="field" required/>
                    </div>
                    <h5>Step 2 of 2</h5>
                    <span class="progress"><span style="width: 100%">&nbsp;</span></span>
                    <input class="email-btn button" type="submit" value="Send" />
                </form>
            </div>

 ...

 <script>

 $('.email-btn').click(function() {

    var email = $("#email").val();

    if (email == ''){
        alert('Please enter your email');
    }

    return false;
});

</script>

I wonder why it still pass the page without any alert evenif it's empty?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.