Urs
Urs

Reputation: 5122

How to change an input's value so it will be passed on when submitting?

With jQuery 1.10.1, I have set the value of an input field as such:

$('.entry input').keyup(function () {
        $('.target input').val(foo);
});

This works on the screen, but when the form is submitted, the value is lost or at least not recognized by PHP validation.

Chrome's inspector doesn't show a value at all:

enter image description here

The examples on http://api.jquery.com/val/ have the same behaviour, in the inspector, the updated value can't be seen.

So how can a submittable value be set via jQuery?

Upvotes: 1

Views: 102

Answers (3)

Isaac Suttell
Isaac Suttell

Reputation: 469

Instead of using a input type="text" you could use as input type="hidden" to store your data. hidden inputs are not visible to the user and are often used to pass data along in forms.

Upvotes: -1

isherwood
isherwood

Reputation: 61056

To follow up on SLaks' answer, you could enable the input on submit:

$('#myForm').submit(function() {
    $(this).('.question input').removeAttr('disabled');
    return true;
});

Upvotes: 1

SLaks
SLaks

Reputation: 887245

That's because of the disabled attribute.

Disabled inputs are not submitted to the server.

To fix this, remove the disabled attribute before submitting.

Upvotes: 4

Related Questions