HTMLでformを作らずにJavaScriptでPOST送信

フォーム自動入力して結果出力なんて処理を作るときに便利

function submitForm( value ){
    var form = document.createElement( ‘form’ );
    document.body.appendChild( form );
    var input = document.createElement( ‘input’ );
    input.setAttribute( ‘type’ , ‘hidden’ );
    input.setAttribute( ‘name’ , ‘myvalue’ );
    input.setAttribute( ‘value’ , value );
    form.appendChild( input );
    form.setAttribute( ‘action’ , ‘example.php’ );
    form.setAttribute( ‘method’ , ‘post’ );
    form.submit();
}

ネタ元