Page 1 of 1

onclick doesn't work

Posted: Sat Jun 14, 2008 10:17 am
by junjustkim
hi to all! I know it is quiet simple question but I am only a newbie. I made a php code using dreamweber for registration of new user. My problem now is I call the javascript function in "onclick" as my reset button but it doesn't work. It was run with the browser but If I click the reset it will proceed to the "action = register.php" instead of clearing the fields. Please help me

Please see the code

Thanks in advance

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
   function SubmitForm()
     {
        var form = document.forms[0];
        var vRequired = true;
        if ((form.UserName.value.length < 1) ||
            (form.EmailAds.value.length < 1) ||
            (form.ConfirmEmail.value.length < 1)
           )
           {
             alert ("Please fill up all the fields.");
             vRequired = false;
           }
           
           if (!vRequired) return flase;
           
           form.submit();
     }
     
   function ResetForm() 
     {
        var form = document.forms[0];
        form.UseName.value = "";
        form.EmailAds.value = "";
        form.ConfirmEmail.value = "";
     }
</script>
</head>
 
<body>
<div align="left">
  <form id="frmRegister" name="frmRegister" method="post" action="register.php">
    <div align="left">
      <table width="400" border="0" cellspacing="1" cellpadding="1">
            <tr>
              <td colspan="4"><b>Registration Form</b></td>
            </tr>
            <td>&nbsp;</td>
            <tr height="20">
              <td height="26"><div align="left">User Name:</div></td>
              <td height="26" align="left"><input type="text" name="UserName" id="UserName" value="<?php echo $_SESSION['UserName']  ?>" /></td>
            </tr>
            <tr>
              <td height="26"><div align="left">E-mail Address:</div></td>
              <td height="26" align="left"><input type="text" name="EmailAds" id="EmailAds"  value="<?php echo $_SESSION['EmailAds']?>"/></td>
            </tr>
            <tr>
              <td height="26"><div align="left">Confirm E-mail Address:</div></td>
              <td height="26"><input type="text" name="ConfirmEmail" id="ConfirmEmail" value="<?php echo $_SESSION['ConfirmEmail']?>"/> </td>
            </tr>
            <tr>
              <td height="26"><div align="left">Password:</div></td>
              <td height="26"><input type="password" name="Password" id="Password" value="<?php echo $_SESSION['Password']?>"/> </td>
            </tr>
            <tr>
              <td height="26"><div align="left">Confirm Password:</div></td>
              <td height="26"><input type="password" name="ConfirmPassword" id="ConfirmPassword" value="<?php echo $_SESSION['ConfirmPassword']?>"/> </td>
            </tr>                               
            <tr>
               <td height="26">
               <td height="26"><input type="submit" name="reset" id="reset" value="Reset" onclick= "ResetForm();" />
               &nbsp;&nbsp;&nbsp;<input type="submit" name="submit" id="submit" value="Submit" onclick="SubmitForm(); Return False;" /></td>
            </tr>                          
      </table>
    </div>
  </form>
</div>
</body>
</html>
 

Re: onclick doesn't work

Posted: Sat Jun 14, 2008 11:29 am
by JAB Creations
This thread has nothing to do with PHP and belongs in the clientside forum. If you want an answer to your question I highly recommend taking the five seconds to read the forum descriptions before you post in the incorrect forum. Posting in the wrong forum will greatly reduce the chances of someone being able to help you.

Re: onclick doesn't work

Posted: Sat Jun 14, 2008 12:29 pm
by hansford
JAB is right, you'll get a quicker answer if you post it to the correct form. If your going to try and call a js function within a submit button then you have to do a return onclick="return validate();"

Code: Select all

 
<script language='javascript'>
function validate(){
//do whatever 
//then you must return true for the form to submit or false 
}
</script>