0

I am very basic jquery user, I mostly get from tutorials and examples to use them on my website. Here is the code I got from 1 tutorial:

$(document).ready(function(){
var form = $('form');
var submit = $('#submit');

form.on('submit', function(e) {
    // prevent default action
    e.preventDefault();
    // send ajax request
    $.ajax({
        url: 'ajax_comment.php',
        type: 'POST',
        cache: false,
        data: form.serialize(), //form serizlize data
        beforeSend: function(){
            // change submit button value text and disabled it
            submit.val('Submitting...').attr('disabled', 'disabled');
        },
        success: function(data){
            // Append with fadeIn see http://stackoverflow.com/a/978731
            var item = $(data).hide().fadeIn(800);
            $('.comment-block').append(item);

            // reset form and button
            form.trigger('reset');
            submit.val('Submit Comment').removeAttr('disabled');
        },
        error: function(e){
            alert(e);
        }
    });
});
});

I have no idea how to make this script to work only on one form that has ID "form1111". I suppose it has to do with var form = $('form');. Please help.

Thank you in advance

2 Answers2

2
var form = $('#form1111');

Id starts with the hash symbol #.

In case you have to pick the class use dot .

var aClass = $('.myClass1111');

Hope this helps. Thank you.

UserProg
  • 629
  • 1
  • 8
  • 22
  • ok, god damn me, I swear I tried this, but other forms kept on using this jquery. Now, I tried again and it works like charm.... Thank you – user3137740 Feb 05 '15 at 07:37
  • I am glad to help. Please consider to accept this as an answer. Thanks :-) – UserProg Feb 05 '15 at 07:39
1

use id instade of "form". "#" symbole is use for id attribute and "." for class attribute of element

var form = $('#form1111');
Nishit Maheta
  • 6,021
  • 3
  • 17
  • 32