I am trying to send an XMLHttpRequest to an external form which contains a textarea and a checkbox. I would like to substitute the text inside the textarea (“Put your text in this box”) for another string and to uncheck the checkbox, then sending the form and getting the results. The form is more or less like this:
<form name="aspnetForm" method="post" action="Tagger.aspx" id="aspnetForm" enctype="multipart/form-data">
<input id="checkBoxOptions_0" type="checkbox" name="checkBoxOptions$0" checked="checked" />
<textarea name="$txtbxInput" id="_txtbxInput">Put your text in this box.</textarea>
<textarea name="$txtbxOutput" readonly="readonly" id="_txtbxOutput" class="output">Output box</textarea>
<input type="submit" name="$btnTagIt" value="Tag It" id="_btnTagIt" class="sizeTopMargin" />
</form>
And I have tried the XMLHttpRequest with two different options: the first one gets back the textarea with the original string and the checkbox checked as default, the second one gives the error explained in one of its lines.
Option 1:
var data = "checkBoxOptions$0.checked=false"+"&$txtbxInput=New String Inserted";
var xhr = new XMLHttpRequest();
xhr.open('POST', "http://nlpdotnet.com/services/Tagger.aspx", true);
xhr.setRequestHeader("Content-type", "multipart/form-data");
xhr.onload = function () {
var results = xhr.response;
}
xhr.send(data);
Option 2:
var formElement = document.getElementById("aspnetForm");
var formData = new FormData(formElement);//TypeError: Argument 1 of FormData.constructor is not an object
formData.append("$txtbxInput", "New String Inserted");
var xhr = new XMLHttpRequest();
xhr.open('POST', "http://nlpdotnet.com/services/Tagger.aspx", true);
xhr.setRequestHeader("Content-type", "multipart/form-data");
xhr.onload = function () {
var results = xhr.response;
}
xhr.send(formData);
As the form is external, I cannot redesign any part of it. Any ideas? Thanks!