Jump to content

Ajax post help!


six

Recommended Posts

Hello,
I'm having trouble with posting data from a dynamic collection.

my code:
[code=php:0]

function TestPost(strForm){

xmlHttp=GetXmlHttpObject()
var str = FormCollection(strForm);
//var str = "firstname=ken&lastname=scott";
var url = "post.asp";
xmlHttp.open("POST",url,true);
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
xmlHttp.send(str);

}

[/code]

ok, if i use:
var str = "firstname=ken&lastname=scott";
is posts the data no problem every time, the thing is that i have alot of form posts on my site and would like to use a dynamic collection method.

[code=php:0]
function FormCollection(theform){

    querystring='';

    for (var i = 0; i<theform.elements.length; i++) {
if(i==0){
    querystring += theform.elements[i].name + "=" + theform.elements[i].value;
} else {
    querystring += "&" + theform.elements[i].name + "=" + theform.elements[i].value;
}
}

document.getElementById("result").innerHTML = querystring; // for testing only
}
[/code]

which will build a string like this: "firstname=ken&lastname=scott" from my current form, the problem is, that it only actually added the string to the date when i staticly enter the data, when i use :
var str = FormCollection(strForm);
it just posts an empty record. yet it return the correct string with i write it out to a <div>. i was hoping that someone here might have some idea what i can do to make this work..

hoping this is the correct forum for this issue.

thanks in advance for your time!
-Ken
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.