bollo
bollo

Reputation: 1634

jQuery hidden value not being sent

Is there a certain or special of dealing with hidden fields in jQuery? I am using a hidden input field and am not receiving a value. Obviously, my code is incorrect and would be grateful if someone could show me the error. many thanks

<input id="customer" name="customer" type="hidden" value="<?php echo $_SESSION['kt_idcode_usr']; ?>" />


$('#submit').click(function () {

        var name = $('.uname').val();
        var customer = $('.customer').val();
        var department = $('#department').val();
        var email = $('.email').val();
        var position = $('.position').val();
        var feedback = $('.feedbacknew').val();
        var data = 'uname=' + name +
                   '&customer=' + customer +
                   '&department=' + department +
                   '&email=' + email +
                   '&position=' + position +
                   '&feedbacknew=' + feedback;
        $.ajax({
            type: "POST",
            url: "feedback.php",
            data: data,
            success: function (data) {
                $("#feedback").get(0).reset();
                $('#message').html(data);
                //$("#form").dialog('close');
                $("#flex1").flexReload();





            }
        });
        return false;

    });

Upvotes: 0

Views: 340

Answers (7)

Itai Sagi
Itai Sagi

Reputation: 5615

may I suggest serialize()?

Upvotes: 1

Mo Valipour
Mo Valipour

Reputation: 13486

I can see that for customer you are using jquery selector ".customer" which searches for an element with class name "customer" but your input has id equal to this, so:

var customer = $('#customer').val();

Upvotes: 1

marto
marto

Reputation: 4493

note the difference:

alert($('.customer').val());

and

alert($('#customer').val());

. is for classes, see http://api.jquery.com/category/selectors/

Upvotes: 1

Londeren
Londeren

Reputation: 3331

$('.customer').val(); ???

not ., # result

$('#customer').val(); // works

Upvotes: 4

Mark Withers
Mark Withers

Reputation: 1482

This line of code is wrong

var customer = $('.customer').val();

you have defined your hidden field by id, not by class, so you would need to use a # instead of a . on the selector

var customer = $('#customer').val();

Upvotes: 2

genesis
genesis

Reputation: 50966

try changing

    var customer = $('.customer').val();

to

    var customer = $('#customer').val();

you don't have such a class customer anywhere in this code

Upvotes: 2

aroth
aroth

Reputation: 54806

The line you have here:

var customer = $('.customer').val();

...is looking for elements with a class called "customer". You don't have any such element. You have an element with an id of "customer". I suspect it will work if you simply change this line to:

var customer = $('#customer').val();

I'd suggest doing this for the rest of your input fields as well. Generally you'll want to identify them by id when collecting values to submit the form. Identifying them by class is typically more for things like styling different kinds of fields, binding event handlers, and so on.

Upvotes: 1

Related Questions