views:

207

answers:

2

What is the simplest way to dynamically create a hidden input form field using jquery?

+5  A: 
$('#myformelement').append('<input type="hidden" name="myfieldname" value="myvalue" />');
Mark B
+6  A: 
$('<input>').attr('type','hidden').appendTo('form');

To answer your second question:

$('<input>').attr({
    type: 'hidden',
    id: 'foo',
    name: 'bar'
}).appendTo('form');
David
Is it possible to add id and name attributes on the fly???????
Mithun P
thank you David
Mithun P