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 4 of 4
  1. #1
    New Coder
    Join Date
    May 2004
    Posts
    73
    Thanks
    0
    Thanked 0 Times in 0 Posts

    simple form control not working

    Heya, this is my first post here.

    Now that I understand a bit of javascript I'm going through my apps and removing php form control and adding javascript. The basic 'did you complete all required fields' stuff. Obviously javascript is better because it will do it before you leave the page.

    Well, on one page it's not working; it just lets the user glide on to the next page without input and without the err msg. I don't see how it's significantly different than any other page.

    Here's the code.

    <?php
    include("functions.php");
    secure();
    $dbconnect=@mysql_connect("localhost","###","###");
    if (!$dbconnect) {
    die ("Error: No connection to the server established. ".mysql_error());
    }
    mysql_select_db("pmap");
    ?>

    <script>
    self.resizeTo(460,460);
    </script>

    <HTML>
    <head>
    <title>THE SEXTANT</title>
    <link rel="stylesheet" type="text/css" href="main.css">

    <script>
    function validate()
    {
    old=mainform.old_password.value;
    new=mainform.new_password.value;

    fail=0;

    if (old=='')
    {
    fail=1;
    }

    if (new=='')
    {
    fail=1;
    }

    if (fail==1)
    {
    alert('Please complete all fields.');
    event.returnValue=false;
    }
    }
    </script>

    </head>
    <body>
    <center><img src="./images/step_one.jpg"></center>

    <center><table align=center border="0"></center>
    <tr><td class="noBorder" valign="top">
    <img src="./images/sextant_background.jpg">

    <div id="menu">
    <form name="mainform" action="passchangeaction.php" method="post" onsubmit="validate();">
    <center><table></center>
    <tr><td>
    Old Password:</td><td><input type="password" name="old_password" size="10"></input></td></tr><td>
    New Password:</td><td><input type="password" name="new_password" size="10"></input></td></tr>
    <tr><td>&nbsp</td></tr>
    <tr><td align=center colspan=2><input type="Submit" value="Update Password"></td></tr>
    </table>
    </form>
    </table>
    </div>

    <div id="nav">
    <center><A HREF="index.php"><img src="./images/back_arrow.gif" alt="Back" border=0></A> <A

    HREF="index.php"><img src="./images/up_arrow.gif" alt="Home" border=0></A></center>
    </div>

    </body>
    </html>
    Last edited by questor; 05-14-2004 at 08:22 AM.

  • #2
    New Coder
    Join Date
    May 2004
    Posts
    73
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Okay, so I just changed the var names 'old' and 'new' to 'oldpassword' and 'newpassword' and it worked.

    Wt?

    So what, old and new are reserved terms?

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,043
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Code:
    function validate(f) 
    {
       if (f.old_password.value==''){
          alert("Old password is empty.");
          f.old_password.focus();
          return false;
       }
       if (f.new_password.value==''){
          alert("New password is empty.");
          f.new_password.focus();
          return false;
       } 
       return true;
    }
    ...
    <form name="mainform" action="passchangeaction.php" method="post" onsubmit="return validate(this);">
    ...
    <input type="Submit" value="Update Password" />
    </form>
    But definitely, you should ALWAYS validate on the server-side. Don't rely on javascript as this can be disabled.

  • #4
    New Coder
    Join Date
    May 2004
    Posts
    73
    Thanks
    0
    Thanked 0 Times in 0 Posts
    damnit. you're right. > I just went through and changed all this stuff to javascript.


  •  

    Posting Permissions

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