开发者

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 +
                开发者_Python百科   '&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;

    });


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

not ., # result

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


try changing

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

to

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

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


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();


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.


note the difference:

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

and

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

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


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();


may I suggest serialize()?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜