Advertisement
dwhitzzz

Append hidden input to form

May 30th, 2019
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /** append an hidden input to a form */
  2. function dynamicAddElementToForm( htmlForm, key, value )
  3. {
  4.     var obj = $("[name='"+ key +"']");
  5.     if( obj.length ){
  6.         obj.val(value);
  7.     }else {
  8.         var inputHiddenTemp = document.createElement('input');
  9.         inputHiddenTemp.type = 'hidden';
  10.         inputHiddenTemp.name = key;
  11.         inputHiddenTemp.value = value;
  12.         htmlForm.appendChild( inputHiddenTemp );
  13.     }
  14. }
  15.  
  16. /** use example */
  17. var htmlForm = document.forms[IR_LocalNomeForm];
  18.     dynamicAddElementToForm(htmlForm, "unParametroX", "true" );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement