Search code examples
jqueryeventsclickinteraction

write into input-hidden-field using jquery


hey there i have this little script:

http://jsfiddle.net/tr0y/6KNRc/

But instead of displaying the "data-id" in the frontend, i want it to be saved in an input-hidden-field, so i added:

<input type="hidden" name="dump" id="dump" value="">

when i submitted the form, i did:

var_dump($_POST);

there was just an empty array,so.. how to do that? greetings


Solution

  • Here is your updated fiddle: http://jsfiddle.net/6KNRc/10/

    Use this:

    $('#dump').val( JSON.stringify(data) );
    

    in place of:

    $('#dump').text( JSON.stringify(data) );
    

    Use jquery's val() to change input values. Use text() to change the text of elements. Since inputs don't have text, it wasn't working for you.