www.webdeveloper.com
Results 1 to 7 of 7

Thread: Help with submit script

  1. #1
    Join Date
    May 2003
    Posts
    21

    Help with submit script

    Hi,

    I have written a really simple script that is called on submit on a web form.

    Checkname does an ajax call to check if a username is taken in a database, if it is free the field check is set to "true".

    When I submit the form the alert pops up with Yep, but then I get an error on submit line.

    Webpage error details

    Message: Object doesn't support this property or method

    Here is the function

    function checkusername() {
    checkname(document.register.username.value);
    if (document.register.check.value=='true'){
    alert('yep');
    document.register.submit();
    }else{
    alert('Please check the username is free')
    }
    }

    Any ideas what can be wrong (the form IS called register)???

    Many Thanks

    Richard

  2. #2
    Join Date
    Apr 2006
    Location
    Houston
    Posts
    1,374
    You may have a JS var called register somewhere else in your code.

    I've gotten tired of all the weird behavior I get when referring to forms by name and started using the ID instead.
    Code:
    <form id="frmRegister"....>
    .
    .
    frmObj = document.getElementById('frmRegister');
    frmObj.submit();

  3. #3
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    What type of input is the field check?
    At least 98% of internet users' DNA is identical to that of chimpanzees

  4. #4
    Join Date
    May 2003
    Posts
    21
    Alas, No joy!

    Here is a cut down version of the code if it helps?

    Code:
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    
    <script src="checkname.js"></script>
    <script language="javascript"> 
    <!--
    function checkusername() {
    	if (document.frmRegister.check.value=='true'){
    		alert('yep');
    		frmObj = document.getElementById('frmRegister');
    		frmObj.submit();
    	}else{
    		alert('Please check the username is free')	
    	}
    }
    -->
    </script>
    </head>
     
    <body>
        <form id="frmRegister" name="frmRegister" method="post" action="">
        <input name="username" type="text" class="inputbox" id="username" tabindex="11" value="" size="26" maxlength="20" onblur="checkname(document.frmRegister.username.value);return false" />
        <div id="testresult">
        	<input type="hidden" name="check" value="false">
        </div>
        <input name="submit" type="button" id="submit" value="Submit" class="button" onClick="checkusername()" />
    </body>
    
    </html>

  5. #5
    Join Date
    May 2003
    Posts
    21
    Quote Originally Posted by Fang View Post
    What type of input is the field check?
    Hidden - see code above

  6. #6
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Code:
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    
    <script src="checkname.js"></script>
    <script type="text/javascript">
    function checkusername() {
    	if (document.frmRegister.check.value=='true'){
    		alert('yep');
    		return true;
    	}else{
    		alert('Please check the username is free');
                    return false;	
    	}
    }
    </script>
    </head>
     
    <body>
        <form id="frmRegister" name="frmRegister" method="post" action="" onsubmit="return checkusername();">
        <input name="username" type="text" class="inputbox" id="username" tabindex="11" value="" size="26" maxlength="20" onblur="checkname(document.frmRegister.username.value);return false" />
        <div id="testresult">
        	<input type="hidden" name="check" value="false">
        </div>
        <input name="submit" type="submit" id="submit" value="Submit" class="button"/>
    </form>
    </body>
    
    </html>
    At least 98% of internet users' DNA is identical to that of chimpanzees

  7. #7
    Join Date
    May 2003
    Posts
    21
    Thank you thats great

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles