Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    May 2006
    Posts
    152
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Posting Form Error

    Hello,

    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?

    Thanks,

    FuZion

  • #2
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    You can't have a hidden field named 'submit' and submit the form using JS.

    http://lists.evolt.org/archive/Week-...17/064069.html

    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #3
    Regular Coder
    Join Date
    May 2006
    Posts
    152
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Ok, thanks for the heads up. I guess I could use AJAX to post the variables to the page, no?

  • #4
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    You could use a hidden form field named something other than 'submit'

    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #5
    Regular Coder
    Join Date
    May 2006
    Posts
    152
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Well, I decided to use AJAX to speed things up a bit. However, there is a problem that I cannot figure out.

    Code:
    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;
    		}
    	};
    	xmlHttp.send(postVars);
    }
    
    function start( num ) {
    	var username = "usernamehere"
    	var x = 0;
    	while ( x < num ) {
    		
    		var username2 = username + x;
    		var email = "emailhere"
    		
    		sendinfo( username2 ,  email );
    		x++;
    	}
    }
    </script>
    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?

    Thanks,

    FuZion
    Last edited by FuZion; 12-22-2006 at 11:47 PM.

  • #6
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    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.:
    Code:
    if (xmlHttp.readyState == "4" && xmlHttp.status=='200') {
    //do whatever
    }


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •