Jump to content

not able to submit a form with javascript


Piyush

Recommended Posts

i have an register page on my website....it has an javascript function which validates the details entered by the user...after validating the form it submits the formlike this..document.registerform.submit();where registerform is the name of the form...but i get an error that Objects doesn't supports that property or method... :) Please help me out...!!!thank u..

Link to comment
Share on other sites

no link or code?just from your description I would suggest switching form using the old dot notation method you are using in favor of using document.getElementById()

Link to comment
Share on other sites

no link or code?just from your description I would suggest switching form using the old dot notation method you are using in favor of using document.getElementById()
Sorry for no code..?
<?php/** * @author Piyush * @copyright 2010 */ if ($_POST['submit']) {require("../function.php");$username=$_POST['username'];$firstname=$_POST['firstname'];$lastname=$_POST['lastname'];$dob=mktime(0,0,0,$_POST['dob_month'],$_POST['dob_day'],$_POST['dob_year']);$gender=$_POST['gender'];$password=$_POST['password'];$secuirtyquestion=$_POST['securityquestion'];$securityanswer=$_POST['securityanswer'];dbget("INSERT INTO data (username,firstname,lastname,password,dob,gender,secretq,secreta,active,profile_pic) VALUES ('".$_POST['username']."','".$_POST['firstname']."','".$_POST['lastname']."','".$_POST['password']."',".$dob.",".$gender.",'".$secuirtyquestion."','".$securityanswer."',1,'common.jpg')");$reget=dbget("SELECT * FROM data WHERE id = ".odbc_result(dbget("SELECT max(id) AS maxid FROM data"),"maxid"));setcookie("username",odbc_result($reget,"username"));setcookie("valid",1);dbget("UPDATE data SET active=1 WHERE id=".odbc_result($reget,"id"));setcookie("id",odbc_result($reget,"id"),0,'/');header("Location:aboutme.php?h=".mt_rand());}?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"><html><head><link href="../style.css" rel="stylesheet" type="text/css" /><script type="text/javascript" src="../ajax/jquery.js"></script><script type="text/javascript" src="../ajax/main.js"></script><title>Piyush's Connect Register</title><style type="text/css">.border{    border: solid 1px #E4E4E4;    width: 350px;}.border:hover{    border: solid 1px #B9B9B9;}.header{    font-weight: bolder; font-size: x-large;    padding: 2px;    }body{    background-image: url('memberback.png');    background-repeat: repeat-x;}</style><script type="text/javascript">function checkusername(){    $("#usernameerror").load("checkusername.php",{'username':document.registerform.username.value,'sid':Math.random()});}function frmproces(){    if (usernameerror==1)    {        alert("Username is not Available");    }        if (document.registerform.username.value=="")    {        alert("Please enter a Username");        document.registerform.username.focus();        return;            }    if (document.registerform.firstname.value=="")    {        alert("Please enter your Firstname");        document.registerform.firstname.focus();        return;            }    if (document.registerform.dob_day.value=="" || document.registerform.dob_month.value=="" || document.registerform.dob_year.value=="")    {        alert("Please Enter a correct Date");        document.registerform.dob_day.focus();        return;            }    if (document.registerform.password.value=="")    {        alert("Please enter a Password");        document.registerform.password.focus();        return;            }    if (document.registerform.password.value!=document.registerform.confirmpassword.value)    {        alert("Passwords do not match");        document.registerform.confirmpassword.focus();        return;            }    if (document.registerform.securityquestion.value=="")    {        alert("Please Enter a Security Question");        document.registerform.securityquestion.focus();        return;    }    if (document.registerform.securityanswer.value=="")    {        alert("Please Enter a Answer for your Security Question");        document.registerform.securityanswer.focus();        return;    }                if (isValidDate(document.registerform.dob_day.value+"/"+document.registerform.dob_month.value+"/"+document.registerform.dob_year.value)==false)    {        alert("Please Enter a Correct Date");        document.registerform.dob_day.focus();        return;            }      document.getElementsByName("registerform")(0).submit();}</script></head><body><script type="text/javascript">usernameerror=0;</script><div id="spiffycalendar" class="text"></div><form action="member_add.php" method="post" name="registerform" id="registerform"><table style="margin-left: 50px;"><tr><td><img src="../pic/shortlogo.png" align="middle"/><span style="font-weight: bolder; color: #04ECBE; font-size: x-large;">Create an Piyush Connect Account</span></td><td></td></tr><tr><td colspan="2" align="center">Just fill in the following details to <b>Register</b></td></tr><tr><td><table class="border" width="100%" cellspacing="10"><tr><td style="background-color: #C5EAFE;" colspan="2"><span class="header">Personal Information</span></td></tr><tr><td><b>Username</b></td><td><input type="text" name="username" value="<?=$_POST['username']?>" onkeyup="checkusername()"/></td></tr><tr><td></td><td id="usernameerror"></td></tr><tr><td><b>First Name</b></td><td><input type="text" name="firstname" value="<?=$_POST['firstname']?>"/></td></tr><tr><td><b>Last Name</b></td><td><input type="text" name="lastname" value="<?=$_POST['lastname']?>"/></td></tr><tr><td><b>Gender</b></td><td width="300px"><select name="gender"><option value="1" >Male</option><option value="2" <?php if ($_POST['gender']==2) { echo "selected='selected'"; }?>>Female</option></select></td></tr><tr><td><b>Birth Date</b></td><td><input type="text" name="dob_day" size="2" value="<?=$_POST['dob_day']?>"/>   <input type="text" name="dob_month" size="2" value="<?=$_POST['dob_month']?>"/>   <input type="text" name="dob_year" size="4" value="<?=$_POST['dob_year']?>"/></td></tr></table></td></tr><tr><td><table class="border" width="100%" cellspacing="10"><tr><td style="background-color: #C5EAFE;" colspan="2"><span class="header">Password Options</span></td></tr><tr><td><b>Password</b></td><td><input type="password" name="password"/></td><td id="passworderror"></td></tr><tr><td><b>Confirm Password</b></td><td><input type="password" name="confirmpassword"/></td></tr><tr><td><b>Your Security Question</b></td><td><input type="text" name="securityquestion" value="<?=$_POST['secuirtyquestion']?>"/></td></tr><tr><td><b>Security Question Answer</b></td><td><input type="text" id="securityanswer" value="<?=$_POST['securityanswer']?>"/></td></tr></table></td></tr><tr><td style="padding: 5px;" ><input value="Register" class="button" type="button" onclick="frmproces()"/></td></tr></table><input type="hidden" name="submit" value="submit"/></form></body>

here's the code...i have tried using this...document.getElementsByName("registerform")(0).submit();but still it gives the same error

Link to comment
Share on other sites

That's not correct either, ditch the form name and give it an ID, and use document.getElementByID to access it. Do the same for all of the form elements, they still need a name to submit but in the Javascript code you should be accessing them by ID.

Link to comment
Share on other sites

That's not correct either, ditch the form name and give it an ID, and use document.getElementByID to access it. Do the same for all of the form elements, they still need a name to submit but in the Javascript code you should be accessing them by ID.
thnks.. for suggestion...
Link to comment
Share on other sites

Hi!Try This Code:Changes:Use "Submit Button", <input type="submit"> & Remov <input type="button">Use: onSubmit="return frmproces();" in <form> tag.Use: "return false;" in javascript "function abc()"Remove: document.getElementsByName("registerform")(0).submit();When "return will not be false"! Form Will Be Redirect To "<form action="member_add.php>"getElementById(id) Is Better Than "element name"Try To Use getElementById(id)But! It'll Work Too.

<?php/** * @author Piyush * @copyright 2010 */if ($_POST['submit']){	require("../function.php");	$username=$_POST['username'];	$firstname=$_POST['firstname'];	$lastname=$_POST['lastname'];	$dob=mktime(0,0,0,$_POST['dob_month'],$_POST['dob_day'],$_POST['dob_year']);	$gender=$_POST['gender'];	$password=$_POST['password'];	$secuirtyquestion=$_POST['securityquestion'];	$securityanswer=$_POST['securityanswer'];	dbget("INSERT INTO data (username,firstname,lastname,password,dob,gender,secretq,secreta,active,profile_pic) VALUES ('".$_POST['username']."','".$_POST['firstname']."','".$_POST['lastname']."','".$_POST['password']."',".$dob.",".$gender.",'".$secuirtyquestion."','".$securityanswer."',1,'common.jpg')");	$reget=dbget("SELECT * FROM data WHERE id = ".odbc_result(dbget("SELECT max(id) AS maxid FROM data"),"maxid"));	setcookie("username",odbc_result($reget,"username"));	setcookie("valid",1);	dbget("UPDATE data SET active=1 WHERE id=".odbc_result($reget,"id"));	setcookie("id",odbc_result($reget,"id"),0,'/');	header("Location:aboutme.php?h=".mt_rand());}?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><link href="../style.css" rel="stylesheet" type="text/css" /><script type="text/javascript" src="../ajax/jquery.js"></script><script type="text/javascript" src="../ajax/main.js"></script><title>Piyush's Connect Register</title><style type="text/css">.border{    border: solid 1px #E4E4E4;    width: 350px;}.border:hover{    border: solid 1px #B9B9B9;}.header{    font-weight: bolder; font-size: x-large;    padding: 2px;    }body{    background-image: url('memberback.png');    background-repeat: repeat-x;}</style><script type="text/javascript">function checkusername(){    $("#usernameerror").load("checkusername.php",{'username':document.registerform.username.value,'sid':Math.random()});}function frmproces(){    if (usernameerror==1)    {        alert("Username is not Available");		return false;    }        if (document.registerform.username.value=="")    {        alert("Please enter a Username");        document.registerform.username.focus();        return false;            }    if (document.registerform.firstname.value=="")    {        alert("Please enter your Firstname");        document.registerform.firstname.focus();        return false;            }    if (document.registerform.dob_day.value=="" || document.registerform.dob_month.value=="" || document.registerform.dob_year.value=="")    {        alert("Please Enter a correct Date");        document.registerform.dob_day.focus();        return false;            }    if (document.registerform.password.value=="")    {        alert("Please enter a Password");        document.registerform.password.focus();        return false;            }    if (document.registerform.password.value!=document.registerform.confirmpassword.value)    {        alert("Passwords do not match");        document.registerform.confirmpassword.focus();        return false;            }    if (document.registerform.securityquestion.value=="")    {        alert("Please Enter a Security Question");        document.registerform.securityquestion.focus();        return false;    }    if (document.registerform.securityanswer.value=="")    {        alert("Please Enter a Answer for your Security Question");        document.registerform.securityanswer.focus();        return false;    }                if (isValidDate(document.registerform.dob_day.value+"/"+document.registerform.dob_month.value+"/"+document.registerform.dob_year.value)==false)    {        alert("Please Enter a Correct Date");        document.registerform.dob_day.focus();        return false;            }}</script></head><body><script type="text/javascript">usernameerror=0;</script><div id="spiffycalendar" class="text"></div><form action="member_add.php" method="post" name="registerform" id="registerform" onSubmit="return frmproces();"><table style="margin-left: 50px;"><tr><td><img src="../pic/shortlogo.png" align="middle"/><span style="font-weight: bolder; color: #04ECBE; font-size: x-large;">Create an Piyush Connect Account</span></td><td></td></tr><tr><td colspan="2" align="center">Just fill in the following details to <b>Register</b></td></tr><tr><td><table class="border" width="100%" cellspacing="10"><tr><td style="background-color: #C5EAFE;" colspan="2"><span class="header">Personal Information</span></td></tr><tr><td><b>Username</b></td><td><input type="text" name="username" value="<?=$_POST['username']?>" onkeyup="checkusername()"/></td></tr><tr><td></td><td id="usernameerror"></td></tr><tr><td><b>First Name</b></td><td><input type="text" name="firstname" value="<?=$_POST['firstname']?>"/></td></tr><tr><td><b>Last Name</b></td><td><input type="text" name="lastname" value="<?=$_POST['lastname']?>"/></td></tr><tr><td><b>Gender</b></td><td width="300px"><select name="gender"><option value="1" >Male</option><option value="2" <?php if ($_POST['gender']==2) { echo "selected='selected'"; }?>>Female</option></select></td></tr><tr><td><b>Birth Date</b></td><td><input type="text" name="dob_day" size="2" value="<?=$_POST['dob_day']?>"/>   <input type="text" name="dob_month" size="2" value="<?=$_POST['dob_month']?>"/>   <input type="text" name="dob_year" size="4" value="<?=$_POST['dob_year']?>"/></td></tr></table></td></tr><tr><td><table class="border" width="100%" cellspacing="10"><tr><td style="background-color: #C5EAFE;" colspan="2"><span class="header">Password Options</span></td></tr><tr><td><b>Password</b></td><td><input type="password" name="password"/></td><td id="passworderror"></td></tr><tr><td><b>Confirm Password</b></td><td><input type="password" name="confirmpassword"/></td></tr><tr><td><b>Your Security Question</b></td><td><input type="text" name="securityquestion" value="<?=$_POST['secuirtyquestion']?>"/></td></tr><tr><td><b>Security Question Answer</b></td><td><input type="text" id="securityanswer" value="<?=$_POST['securityanswer']?>"/></td></tr></table></td></tr><tr><td style="padding: 5px;" ><input value="Register" class="button" type="submit" /></td></tr></table></form></body></html>

Link to comment
Share on other sites

Hi!Try This Code:Changes:Use "Submit Button", <input type="submit"> & Remov <input type="button">Use: onSubmit="return frmproces();" in <form> tag.Use: "return false;" in javascript "function abc()"Remove: document.getElementsByName("registerform")(0).submit();When "return will not be false"! Form Will Be Redirect To "<form action="member_add.php>"getElementById(id) Is Better Than "element name"Try To Use getElementById(id)But! It'll Work Too.
<?php/** * @author Piyush * @copyright 2010 */if ($_POST['submit']){	require("../function.php");	$username=$_POST['username'];	$firstname=$_POST['firstname'];	$lastname=$_POST['lastname'];	$dob=mktime(0,0,0,$_POST['dob_month'],$_POST['dob_day'],$_POST['dob_year']);	$gender=$_POST['gender'];	$password=$_POST['password'];	$secuirtyquestion=$_POST['securityquestion'];	$securityanswer=$_POST['securityanswer'];	dbget("INSERT INTO data (username,firstname,lastname,password,dob,gender,secretq,secreta,active,profile_pic) VALUES ('".$_POST['username']."','".$_POST['firstname']."','".$_POST['lastname']."','".$_POST['password']."',".$dob.",".$gender.",'".$secuirtyquestion."','".$securityanswer."',1,'common.jpg')");	$reget=dbget("SELECT * FROM data WHERE id = ".odbc_result(dbget("SELECT max(id) AS maxid FROM data"),"maxid"));	setcookie("username",odbc_result($reget,"username"));	setcookie("valid",1);	dbget("UPDATE data SET active=1 WHERE id=".odbc_result($reget,"id"));	setcookie("id",odbc_result($reget,"id"),0,'/');	header("Location:aboutme.php?h=".mt_rand());}?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><link href="../style.css" rel="stylesheet" type="text/css" /><script type="text/javascript" src="../ajax/jquery.js"></script><script type="text/javascript" src="../ajax/main.js"></script><title>Piyush's Connect Register</title><style type="text/css">.border{    border: solid 1px #E4E4E4;    width: 350px;}.border:hover{    border: solid 1px #B9B9B9;}.header{    font-weight: bolder; font-size: x-large;    padding: 2px;    }body{    background-image: url('memberback.png');    background-repeat: repeat-x;}</style><script type="text/javascript">function checkusername(){    $("#usernameerror").load("checkusername.php",{'username':document.registerform.username.value,'sid':Math.random()});}function frmproces(){    if (usernameerror==1)    {        alert("Username is not Available");		return false;    }        if (document.registerform.username.value=="")    {        alert("Please enter a Username");        document.registerform.username.focus();        return false;            }    if (document.registerform.firstname.value=="")    {        alert("Please enter your Firstname");        document.registerform.firstname.focus();        return false;            }    if (document.registerform.dob_day.value=="" || document.registerform.dob_month.value=="" || document.registerform.dob_year.value=="")    {        alert("Please Enter a correct Date");        document.registerform.dob_day.focus();        return false;            }    if (document.registerform.password.value=="")    {        alert("Please enter a Password");        document.registerform.password.focus();        return false;            }    if (document.registerform.password.value!=document.registerform.confirmpassword.value)    {        alert("Passwords do not match");        document.registerform.confirmpassword.focus();        return false;            }    if (document.registerform.securityquestion.value=="")    {        alert("Please Enter a Security Question");        document.registerform.securityquestion.focus();        return false;    }    if (document.registerform.securityanswer.value=="")    {        alert("Please Enter a Answer for your Security Question");        document.registerform.securityanswer.focus();        return false;    }                if (isValidDate(document.registerform.dob_day.value+"/"+document.registerform.dob_month.value+"/"+document.registerform.dob_year.value)==false)    {        alert("Please Enter a Correct Date");        document.registerform.dob_day.focus();        return false;            }}</script></head><body><script type="text/javascript">usernameerror=0;</script><div id="spiffycalendar" class="text"></div><form action="member_add.php" method="post" name="registerform" id="registerform" onSubmit="return frmproces();"><table style="margin-left: 50px;"><tr><td><img src="../pic/shortlogo.png" align="middle"/><span style="font-weight: bolder; color: #04ECBE; font-size: x-large;">Create an Piyush Connect Account</span></td><td></td></tr><tr><td colspan="2" align="center">Just fill in the following details to <b>Register</b></td></tr><tr><td><table class="border" width="100%" cellspacing="10"><tr><td style="background-color: #C5EAFE;" colspan="2"><span class="header">Personal Information</span></td></tr><tr><td><b>Username</b></td><td><input type="text" name="username" value="<?=$_POST['username']?>" onkeyup="checkusername()"/></td></tr><tr><td></td><td id="usernameerror"></td></tr><tr><td><b>First Name</b></td><td><input type="text" name="firstname" value="<?=$_POST['firstname']?>"/></td></tr><tr><td><b>Last Name</b></td><td><input type="text" name="lastname" value="<?=$_POST['lastname']?>"/></td></tr><tr><td><b>Gender</b></td><td width="300px"><select name="gender"><option value="1" >Male</option><option value="2" <?php if ($_POST['gender']==2) { echo "selected='selected'"; }?>>Female</option></select></td></tr><tr><td><b>Birth Date</b></td><td><input type="text" name="dob_day" size="2" value="<?=$_POST['dob_day']?>"/>   <input type="text" name="dob_month" size="2" value="<?=$_POST['dob_month']?>"/>   <input type="text" name="dob_year" size="4" value="<?=$_POST['dob_year']?>"/></td></tr></table></td></tr><tr><td><table class="border" width="100%" cellspacing="10"><tr><td style="background-color: #C5EAFE;" colspan="2"><span class="header">Password Options</span></td></tr><tr><td><b>Password</b></td><td><input type="password" name="password"/></td><td id="passworderror"></td></tr><tr><td><b>Confirm Password</b></td><td><input type="password" name="confirmpassword"/></td></tr><tr><td><b>Your Security Question</b></td><td><input type="text" name="securityquestion" value="<?=$_POST['secuirtyquestion']?>"/></td></tr><tr><td><b>Security Question Answer</b></td><td><input type="text" id="securityanswer" value="<?=$_POST['securityanswer']?>"/></td></tr></table></td></tr><tr><td style="padding: 5px;" ><input value="Register" class="button" type="submit" /></td></tr></table></form></body></html>

thx for this...!!!
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...