javascript( jQuery ) 로 HTML 코드상에 없는 별도의 Form 을 생성 추가하여 Submit 하는 샘플 코드

 

 

function sendDataForm_submit()
{
    let submitExec     = true;
    let Url_formAction = "[ FORM SUBMIT URL ]";
	
	if( submitExec == true )
	{
        jQuery( "#sendDataForm" ).remove();
		jQuery( "body" ).append("<form id='sendDataForm' name='sendDataForm' enctype='multipart/form-data'></form>");

        jQuery( "body" ).append("<form id='sendDataForm' name='sendDataForm'></form>");
        
		let arrTargetField	=	new Array(
			"[TARGET_FIELD_ID_01]"
			,"[TARGET_FIELD_ID_02]"
			,"[TARGET_FIELD_ID_03]"
			,"[TARGET_FIELD_ID_04]"
			,"[TARGET_FIELD_ID_05]"
		);
		
        let html_inputBox	=	"";
        for(let loopCnt=0; arrTargetField.length>loopCnt; loopCnt++ )
        {
            html_inputBox	=	"<input";
            html_inputBox	+=	" type='text'";
            html_inputBox	+=	" name='" + arrTargetField[loopCnt] + "'";
            html_inputBox	+=	" value='" + jQuery("#"+arrTargetField[loopCnt]).val() + "'";
            html_inputBox	+=	">";
            jQuery("#sendDataForm").append( html_inputBox );
        }//	end for
        jQuery("#sendDataForm").attr("action", Url_formAction );
        jQuery("#sendDataForm").attr("method","POST");
        jQuery("#sendDataForm").submit();
        
    }else{
		console.log( jQuery("#sendDataForm") );
    }//	end if
	
}//	end function