/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] extract form values from ajax or iframe

ive tried using ajax and getting the responsetext
ive also tried loading an iframe and extracting the form details from that iframe

but no matter what i try i cant get it to work

here are the 2 separate set of code im trying to get to work.
if you can fix them great, if you got something else that will work, i would gladly use it

the second page is on the same domain, so there is no cross domain errors or anything

[code]
window.onload = function()
{
var createIframe = document.createElement(‘iframe’);
createIframe.setAttribute(‘src’,’/path’);
createIframe.onload = function()
{
alert(‘hello’);
alert(createIframe.document.forms[1].first_name.value);
alert(createIframe.forms[1].first_name.value);
alert(window.frames[0].document.forms[1].first_name.value);
}
document.getElementById(‘iframeholder’).appendChild(createIframe);
}
[/code]

[code]
function getXMLHTTPRequest()
{
var req = false;
try
{
req = new XMLHttpRequest(); /* e.g. Firefox */
}
catch(err1)
{
try
{
req = new ActiveXObject(“Msxml2.XMLHTTP”); /* some versions IE */
}
catch(err2)
{
try
{
req = new ActiveXObject(“Microsoft.XMLHTTP”); /* some versions IE */
}
catch(err3)
{
req = false;
}
}
}
return req;
}

var myRequest = getXMLHTTPRequest();

var http_request = false;
function makePOSTRequest(url, parameters) {
http_request = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,…
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType(‘text/html’);
}
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject(“Msxml2.XMLHTTP”);
} catch (e) {
try {
http_request = new ActiveXObject(“Microsoft.XMLHTTP”);
} catch (e) {}
}
}
if (!http_request) {
//alert(‘Cannot create XMLHTTP instance’);
return false;
}
http_request.onreadystatechange = alertContents;
http_request.open(‘POST’, url, true);
http_request.setRequestHeader(“Content-type”, “application/x-www-form-urlencoded”);
http_request.setRequestHeader(“Content-length”, parameters.length);
http_request.setRequestHeader(“Connection”, “close”);
http_request.send(parameters);
}
function alertContents() {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
//alert(http_request.responseText);
result = http_request.responseText;
//document.getElementById(‘addfriend’).innerHTML = result;
} else {
//alert(‘There was a problem with the request.’);
}
}
}

function callAjax(){
var url=”PATH/TO/SCRIPT”;
myRequest.open(“GET”,url,true);
myRequest.onreadystatechange=responseAjax;
myRequest.send(null);}

function responseAjax(){
if(myRequest.readyState==4){
if(myRequest.status==200){
//alert(“The server said: “+myRequest.responseText);
var div = document.createElement(‘div’);
div.innerHTML = myRequest.responseText;

var val = div.forms.form1.first_name;

alert(val);

}

}
else
{
//failure
}
}
callAjax();
[/code]

thanks

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@nathandelaneSep 28.2009 — It is not very apparent what you are trying to do. From a guess, I suppose that you have an iframe which contains an html document that contains a form. Now are you submitting that form? Why do you want the get the values from that form. If the form and your document containing the iframe are in the same domain, then why are you using an iframe?
Copy linkTweet thisAlerts:
@PaPPyauthorSep 28.2009 — its on a site that i want to extract form details that the server fills in and display it on my profile page

so im trying everything possible to fetch that page, read the contents and display it

but for what ever reason ajax nor iframe, is allowing me dom access to that content

i can get the whole page's innerHTML but not the form or a div tag
×

Success!

Help @PaPPy spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...