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
https://forums.phpfreaks.com/topic/54617-cant-get-thiselements-to-work-in-ajax/
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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.