I think it's a matter of timing. Try to run your script after document has been loaded:
<body onload="loadMe();">
<iframe name = "myframe" id = "myiframe">
</iframe>
<script>
function loadMe() {
var myform2 = document.createElement("form");
var input2 = document.createElement("input");
input2.name = "quantity";
input2.value = "10";
myform2.appendChild(input2);
var getFrame = document.getElementById('myiframe');
var doc = getFrame.contentDocument || getFrame.contentWindow.document;
doc.body.appendChild(myform2); // Does not work.
}
</script>
</body>