5

I'm looking for a way to insert a hidden input on submitting for 'Yes' in my jquery code below.

How do I insert this:

<input type="hidden" name="token" value="1">

From this:

$(function() {
    $( "#dialog" ).dialog({
        autoOpen: false,
        modal: true,
        buttons: {
            "Yes": function() {
                $( '#form' ).submit();
            },
            "No": function() {
                $( '#form' ).submit();
            },
            Cancel: function() {
                $( this ).dialog( "close" );
            }
        }
    });
});
1
  • I do not know if I understood well, but I think that you can append the html code in the tag body Commented Nov 22, 2011 at 18:39

3 Answers 3

14

Try this

$(function() {
    $( "#dialog" ).dialog({
        autoOpen: false,
        modal: true,
        buttons: {
            "Yes": function() {
                $('#form').append('<input type="hidden" name="token" value="1" />').submit();
            },
            "No": function() {
                $('#form').submit();
            },
            Cancel: function() {
                $(this).dialog( "close" );
            }
        }
    });
});
Sign up to request clarification or add additional context in comments.

Comments

7

Easy answer, first adding the input and then calling submit (I'm guessing a bit of context btw).

$('#form').append('<input type="hidden" name="token" value="1">').submit();

1 Comment

+1 for this. Just to make it niftier, I'll do something like that. $('#form').append("'input[name=token]').val(tVal)").submit();
0

I'm new to JQuery but thought others might appreciate this for adding multiple values.

var myFormData = [
    {
        name: 'x_login',
        value: 'xxxxxxxxxx'
    }, {
        name: 'x_amount',
        value: donationAmount
    }
];

$.each(myFormData, function (index, myData) {
    debugger;
    $('#registerformid').append('<input type="hidden" name=' + myData.name + ' value=' + myData.value + '>');
});

$('#registerformid').submit();

Comments

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.