SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Evangelist spoondevil's Avatar
    Join Date
    Jun 2001
    Location
    Harlow, Essex, UK
    Posts
    426
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Verify that field1 = field2

    I have created a registration script in PHP and want a JS feature embedded to tell the user that the 2 passwords they have typed "haven't" matched. If they are identical, then I want the registration to go through as normal, but if there is an incorrect match, then it should stop the script and open up an alert box stating the error. When the user clicks on the "okay" button in the alert box, the script should not try to carry on with the process.

    I have seen this feature on a number of registration websites, but I have searched Hot Scripts and some other resources to no avail.

    Anyone got any ideas?

    Here is the section of my form that I require to be checked:
    Code:
    <table align="center" cellspacing="2" cellpadding="2" border="0">
    <tr> 
    	<td><p>Username</p></td>
    	<td><p><input name="username" type="text" size="32" maxlegnth="8" /></p></td>
    </tr><tr> 
    	<td><p>Password</p></td>
    	<td><p><input name="password" type="password" size="32" /></p></td>
    </tr><tr> 
    	<td><p>Re-Enter Password</p></td>
    	<td><p><input name="password2" type="password" size="32" /></p></td>
    </tr><tr> 
    	<td><p></p></td>
    	<td><p><input name="submit" type="submit" value="register" /></p></td>
    </tr>
    </table>
    If password2 matches password then I want the process to carry on, otherwise it should stop.


    Regards
    Gunter

  2. #2
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    Change your form to this -
    PHP Code:
    <table align="center" cellspacing="2" cellpadding="2" border="0">
    <
    tr
        <
    td><p>Username</p></td>
        <
    td><p><input name="username" type="text" size="32" maxlegnth="8" /></p></td>
    </
    tr><tr
        <
    td><p>Password</p></td>
        <
    td><p><input id='password' name="password" type="password" size="32" /></p></td>
    </
    tr><tr
        <
    td><p>Re-Enter Password</p></td>
        <
    td><p><input id='password2' name="password2" type="password" size="32" onBlur="checkPass()" /></p></td>
    </
    tr><tr
        <
    td><p></p></td>
        <
    td><p><input name="submit" type="submit" value="register" /></p></td>
    </
    tr>
    </
    table
    and here is the checkPass() function.
    PHP Code:
    function checkPass()
    {
       var 
    pass1pass2;
       
    pass1 document.getElementById('password').valuepass2 document.getElementById('password2').value;

       if ( 
    pass1 != pass2 )
       {
          
    alert("Passwords don't match");
       }


  3. #3
    SitePoint Evangelist spoondevil's Avatar
    Join Date
    Jun 2001
    Location
    Harlow, Essex, UK
    Posts
    426
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for that DJ P@CkMaN

    I really like the way it tells you they don't match as soon as you tab away from it.


    Regards
    Gunter

  4. #4
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    why use /> ?

    What does '/>' do?

    I have seen this alot recently but I don't use it. What is it and does it have to be used?
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if

  5. #5
    SitePoint Evangelist spoondevil's Avatar
    Join Date
    Jun 2001
    Location
    Harlow, Essex, UK
    Posts
    426
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's because in XHTML, every tag must close of with a />. Most tags already have their closing section such as those in the table layout, but the input tags do not have a definite closing point, so you finish them as a />

    That's what I read in Kev's book anyways.


    Gunter

  6. #6
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    Ending tags such as <input> and <img> that don't have a specific closing tag with ' />' is XHTML and also is required if you want your page to comply with the W3C standards.

    Eg -
    Code:
    <img src='file.gif' border='0'> <!-- no no -->
    <img src='file.gif' border='0' /> <!-- yay -->
    
    <a href='file.html'>Clicky</a> <!-- not necessary as anchor has a closing tag -->


Bookmarks

Posting Permissions

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