Solved

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

Posted on 2010-08-26
5
356 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Download a website to hdd 2 49
unset shopping cart session 15 29
A form to still have contents even if some are wrong 10 46
jQuery not working on ELSE... why? 2 19
Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

914 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now