Append enctype="multipart/form-data" to form

Hello,

I suck big time with Javascript and really would need your help right now. I am building a Wordpress plugin and trying to assign an enctype=“multipart/form-data” to write posts form without altering the original application core code.

I am trying this approach and have no results so far (also tried with document.getElementById(“post”))

var theForm = document.getElementsByName(“post”);
theForm.setAttribute(“enctype”, “multipart/form-data”);

Would really appreciate your advice.

Thanks a mil!

Best,
rem.

See this Simple AJAX page which has an example of how to set up for POST and also how to send data to a PHP form - code here is free to use.

Thank you, will definitively have a look!

The code above is cool, will definitively use it for another purposes, thank you. What I was looking for though is:


<script type="text/javascript">
window.onload = function(){
document.getElementById('post').enctype = 'multipart/form-data';
		}
</script>

Just in case someone else might need it as well…

yes that works perfectly. thanks for this. I was looking everywhere on how to change the form attributes and this is the only thing that works