View Full Version : Posting Form Error

12-22-2006, 11:12 PM

I am trying to submit a form with Javascript, however, when I run the script, the Firefox Error Console says that my .submit() function is not a function.

The form I am submitting has a hidden field named submit. When I take this hidden field out, the script runs fine, but when it's in there I get the " form1.submit() is not a function" error.

Any Ideas?



12-22-2006, 11:17 PM
You can't have a hidden field named 'submit' and submit the form using JS.



12-22-2006, 11:22 PM
Ok, thanks for the heads up. I guess I could use AJAX to post the variables to the page, no?

12-22-2006, 11:28 PM
You could use a hidden form field named something other than 'submit'


12-23-2006, 12:44 AM
Well, I decided to use AJAX to speed things up a bit. However, there is a problem that I cannot figure out.

function createXMLRequest() {
if (typeof XMLHttpRequest != "undefined") {
return new XMLHttpRequest();
} else if (window.ActiveXObject) {
var aVersions = [ "MSXML2.XMLHttp.5.0", "MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0", "MSXML2.XMLHttp","Microsoft.XMLHttp" ];
for (var i = 0; i < aVersions.length; i++) {
try {
var xmlHttp = new ActiveXObject(aVersions[i]);
return xmlHttp;
} catch (oError) {
//Do nothing
throw new Error("XMLHttp object could be created.");

function sendinfo( username , email ) {
var form1 = document.getElementById('form1');
var postVars = "username=" + escape( username ) + "&email=" + escape( email ) + "&new_password=pw&password_confirm=pw&coppa=0&submit=1";
var xmlHttp = createXMLRequest();
var file = "http://url.com";
xmlHttp.open ('POST',file,true);
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readystate == "4" || xmlHttp.readyState=="complete") {
document.getElementById('test').innerHTML = "it worked";

} else {
document.getElementById('test').innerHTML = xmlHttp.status;

function start( num ) {
var username = "usernamehere"
var x = 0;
while ( x < num ) {

var username2 = username + x;
var email = "emailhere"

sendinfo( username2 , email );

When I run this, the status returns as 200. I'm not sure exactly what this means, but I know that the ready state is supposed to be 4 to run. And it isn't because it returns a 200 error to me. I'm not sure what is wrong here, maybe it's my post vars?



12-23-2006, 01:47 AM
readyState (note the capital S, you've forgotten it) is 4 when the request is complete. A status of 200 means the request was successful (statuses beginning 2 are success, 3 are for redirects, 4 and 5 are for errors... familiar with '404 page not found' and '500 internal server error'? 200 is the 'success' message in the same vein...) and so you should really be checking for both, i.e.:

if (xmlHttp.readyState == "4" && xmlHttp.status=='200') {
//do whatever