Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8779811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:53:27+00:00 2026-06-13T19:53:27+00:00

I am having strange behaviour when using jquery.on(). Basically, just trying to create a

  • 0

I am having strange behaviour when using jquery.on().

Basically, just trying to create a newsletter signup form (can be dynamically generated and not there on initial DOM load) and pass the details through in Ajax but it is not registering the first click on the submit button meaning that to successfully submit, the user has to click twice (only seeing the success message and ‘subscribe’ post on 2nd click).

The html:

<div class="newsletter-widget grid-item masonry-brick">
    <input name="Email" type="email" placeholder="Please enter your email" required />
    <input type="submit" value="Subscribe" class="newslettersubmit"/>

and the javascript (in document ready);

var newsletterFocus = $('.newsletter-widget').find('input[type=submit]');

$(document).on('submit', newsletterFocus, function (e) {
    e.preventDefault();
    var newsletterLinks = newsletterFocus;
    DD.newsletter.behavior(newsletterLinks);
});

and the functions within an object that are called;

DD.newsletter = {

behavior: function (item) {
    item.click(function (e) {
        e.preventDefault();
        var where = $('.newsletter-widget').find('input[type=submit]').parents('section').attr('id');
        var email = $(this).siblings('[name$=Email]'),
        emailVal = email.val();
        DD.newsletter.subscribe(email, emailVal, where);
    });
},

subscribe: function (self, email, where) {
    $.ajax({
        type: "POST",
        data: '{"email":"' + email + '", "method":"' + where + '"}',
        url: '/Subscriber/Subscribe',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (response) {
            self.val(response);
        },
        failure: function (msg) {
            self.val(msg);
        }
    });
},});

I’ve tried using ‘click’ as the action for on() but this registers an event on each click and i get thousands of forms submitted!

Any help appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T19:53:29+00:00Added an answer on June 13, 2026 at 7:53 pm

    It should probably (I think) be something like this:

    DD.newsletter = {
    
    behavior: function (item) {
            var where = $(item).parents('section').attr('id');
            var email = $(item).siblings('[name$=Email]'),
            var emailVal = email.val();  // why were you declaring this without 'var'?
            DD.newsletter.subscribe(email, emailVal, where);
    },
    
    subscribe: function (self, email, where) {
        $.ajax({
            type: "POST",
            data: '{"email":"' + email + '", "method":"' + where + '"}',
            url: '/Subscriber/Subscribe',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (response) {
                self.val(response);
            },
            failure: function (msg) {
                self.val(msg);
            }
        });
    },});
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using WPF having a strange issue with RadListBox SelectedItem databinding, trying to
I'm having strange behaviour, that can not replicate on local machine and it is
I am having some strange behaviour trying to fix some objects in my MongoDB.
I'm having a strange issue with Azure! I just recently upgraded my azure deployed
I am having a strange issue with jScrollPane plugin. After several days of using
I'm having a strange situation, and I can't figure out the problem. I want
I'm having some strange issues with .removeClass() and .addClass() in jQuery. Specifically it seems
I'm having some strange behaviour ocurring when I try to run my Iphone app
I'm having a strange problem, that I've been trying to solve for too long.
I am having some very strange behavior when using a set (it's actual a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.