Jump to content

can't get this.elements to work in ajax


marf

Recommended Posts

Anybody know if theres something special to get  this.elements[0] working? I basically have my ajaxhttpreq.js which the function in that file has a for loop like

 

...
for(var i=0;i<thisForm.elements.length;i++){
		if(thisForm.elements[i].type == "text"){
			formData = formData + thisForm.elements[i].name + "=" + escape(thisForm.elements[i].value) + "&";
}
...

 

but formData is ALWAYS empty, no matter what. Why is this?

 

I call this function with  onSubmit = "return ajaxreq(this,"myfile.php");" in my <form> tag so that looks legit.

Link to comment
Share on other sites

ok forget everything I said above as I have narrowed down the problem.

 

I use this to call the javascript

 

<form action="add_laptop2.php" onsubmit="return formSubmit(this, 'add_laptop2.php');" method="POST">

 

and then look below

 


function formSubmit(thisForm, pageURL){
   alert(thisForm.elements[0].value); //THIS WORKS AND Shows the Value

   secondFunction(thisForm);
return false;
}

function secondFunction(thisForm){
   alert(thisForm.elements[0].value); //THIS Doesn't show, the alert window shows undefined

}

 

So why does it not show in the second function but in the first one its fine? I tried assigning it to a variable in the first one and passing and still no go... any ideas?

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.