Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2010-08-26
5
Medium Priority
?
365 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
[X]
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
  • 3
  • 2
5 Comments
 
LVL 40

Accepted Solution

by:
Gurvinder Pal Singh earned 2000 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:Gurvinder Pal Singh
ID: 33530345
Thanks for the points
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This article discusses how to implement server side field validation and display customized error messages to the client.
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 how to count occurrences of each item in an array.
Suggested Courses

604 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