0

hello i have a big table of products in each tree there is a form with two inputs. one input is text where the admin can set the product price. the second one is hidden with the value of the product id.

now there is this jquery code.

$(function() {
    $(".form").submit(function() {
        var dyo_id = $(".dyo_id").val();
        var price = $(".setprice").val();

            $.ajax({
                type: 'post',
                url: 'setprice.php',
                data: 'price='+price+'&dyo_id='+dyo_id,
                cache: false,
                success: function(data) {
                    $('.price'+dyo_id).html(data);
                    alert('success');
                }
            });

        return false;
    });

});

the problem is with the variables they select the first inputs of the first product

it's just a simple question how can i select the current inputs that i am on?

sorry for my poor english.

2 Answers 2

1

Why don't you try using serialize()?

$(function() {
    $(".form").submit(function() {
        var dyo_id = $(".dyo_id").val();
        var data_ajax = $(this).serialize(); // <==

            $.ajax({
                type: 'post',
                url: 'setprice.php',
                data: data_ajax,
                cache: false,
                success: function(data) {
                    $('.price'+dyo_id).html(data);
                    alert('success');
                }
            });

        return false;
    });
});
Sign up to request clarification or add additional context in comments.

1 Comment

yeah i don't know what serialize is i need to get a book.
0

Set the context of jquery to this (which is the current form):

    var dyo_id = $(".dyo_id", this).val();
    var price = $(".setprice", this).val();

2 Comments

i'm getting undefined for both of them.?
i'm getting undefined because the forms are in a html table

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.