Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

function runs once, then error: "ïs not a function"

Posted on 2010-08-26
5
358 Views
Last Modified: 2013-11-11
Hi experts,

I have created a javascript function which posts form data for a single form, then goes trough a loop which posts multiple forms. Both these methods use the same function to actually post the data, but when i try to post with the loop it gives a javascript error: "post is not a function" and clicking on the error shows the line

post = post( action, parameters );

Open in new window


But when i called it once before the loop the function was succesfully executed. Very strange.

Below the code that calls the function. The first code shows the single and looped call to a function. The second part is the called function which in turn calls the 3rd function which posts the data using ajax.
// save the main form
result = saveForm( action, what, main );
	
// save the available forms
saveForms( 'address' );
saveForms( 'phone' );
saveForms( 'email' );

---------------------------------------

// the string with the POST data
parameters = 'what=company&id=' + generateId();
	
// add the field names and values to the post data
for( var i = 0; i < form.length; i++ )
{
	// save the form field
	field = form.elements[i];
		
	// add the field to the string
	parameters += '&' + field.name + '=' + field.value;
}

// add the company/contact id
parameters += '&c_id=' + c_id;
	
// post the data
post = post( action, parameters );
	
// return the value
return post;

---------------------------------------

// get the xmlHttp object
xmlHttp = getXmlHttpObject();
	
// open the page
xmlHttp.open( 'POST', '/modules/resources/add.php', false);
	
// set the request headers
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", parameters.length);
xmlHttp.setRequestHeader("Connection", "close");
	
// send the data
xmlHttp.send( parameters );
	
// return the text that's recieved from the server
return xmlHttp.responseText;

Open in new window

0
Comment
Question by:mverschoof
  • 3
  • 2
5 Comments
 
LVL 40

Accepted Solution

by:
gurvinder372 earned 500 total points
ID: 33530140
use a different variable for post

<<      
// post the data
postvar = post( action, parameters );
      
// return the value
return postVar;
>>
0
 
LVL 5

Author Comment

by:mverschoof
ID: 33530267
I'll give it a try. Thanks for your quick reply!

Cheers, Michael
0
 
LVL 5

Author Comment

by:mverschoof
ID: 33530310
I changed both the post variables to a different name and it worked! I was pulling my hair out for two days unable to find it...

Sometimes the answer is so simple. It just needs a different perspective.

Well done!
0
 
LVL 5

Author Closing Comment

by:mverschoof
ID: 33530321
in the example given by gurvinder372, 'post' is replaced by 'postvar' and 'postVar'. These should both be the same... (for future viewer)
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 33530345
Thanks for the points
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Link failure 16 32
Html Newline 7 20
PHP: Best way to scan folders and process files 10 39
On Load function does not trigger on iPhone 4 32
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question