The process works like this:
Using xmlHTTP, get the metadata (datasource URL and the target URL) << works
fine
Using xmlHTTP, "GET" data from the datasource URL << works fine, too
document.location = target URL << works fine
The next step would be to wait until the new location is done loading, then
use the data to fill in the form at the target URL. However, the script dies
at the point just after the document location is set to the target form. The
code of the script is below:
// ==UserScript==
// @name Test 1
// @namespace dt1
// @description Fill out client forms
// @include
https://initiating_page.com
// @include
https://domain_4_the_client_forms/*
// @version 1
// ==/UserScript==
function mainContent(){
var vURL = "
http://metadata_URL";
var myCtl = document.getElementById("divDebug");
var fieldCounter = 0;
myCtl.innerHTML = '<style type="text/css">* {font-family: sans-serif;
font-size: 12px;}</style>';
myCtl.innerHTML += '<div id="divDebug"></div>';
myCtl.innerHTML += '<p>version: 1.0</p>';
myCtl.innerHTML += '<p>Checking datasource: ' + vURL + '</p>';
GM_xmlhttpRequest({
method: "GET",
url: "
http://datasource_url",
onload: function(response) {
parms = response.responseText.split('~~~');
datasource = parms[0];
target = parms[1];
success = parms[2];
failure = parms[3];
GM_xmlhttpRequest({
method: "GET",
url: datasource,
onload: function(response) {
document.location = target;
// << HERE IS WHERE WE BREAK DOWN >>
window.load = function(){
parms = response.responseText.split('~~~');
returnedData = parms[1];
var parser = new DOMParser();
var dom = parser.parseFromString(returnedData, "application/xml");
var fields = dom.getElementsByTagName('field');
var fieldname;
var data;
var datatype;
var formFieldId;
for (var i = 0; i < fields.length; i++) {
fieldname =
fields[i].getElementsByTagName('fieldname')[0].textContent;
data = fields[i].getElementsByTagName('data')[0].textContent;
formFieldId =
fields[i].getElementsByTagName('formfieldid')[0].textContent;
datatype =
fields[i].getElementsByTagName('datatype')[0].textContent;
alert([fieldname, data, formFieldId].join('\n'));
fieldCounter++;
if(fieldCounter == 1) return // just do the first one as a test
}
}
}
});
}
});
}
mainContent();
// --- end
I need the script to wait until the target location is loaded, then continue
and fill out fields in the form. What am I missing?
Thanks!
--
View this message in context:
http://old.nabble.com/Complex-data-entry-in-a-multi-page-web-form-tp33789823p33789823.html
Sent from the GreaseMonkey List mailing list archive at Nabble.com.