Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 26th, 2005, 01:29 PM
Authorized User
 
Join Date: Aug 2005
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default accesing a form with Strict XHTML 1.0

I have made an Strict XHTML 1.0 document with a form as shown below:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

    <head>
        <title>JavaScript One</title>
        <link rel="stylesheet" type="text/css" href="jsOne.css" />
        <script type="text/javascript" src="jsOne.js"></script>        
    </head>

    <body>
        <h1>Form Test</h1>
        <h2>Form Validation One</h2>
        <form action="createAccount.php" method="post" name="formCreateAccount" onsubmit="return validate(this);" >
            <table>
                <tr>
                    <td><b>Create Account</b></td>
                </tr>
                <tr>
                    <td>Username: </td>
                    <td><input type="text" name="textUsername" />#160;(minimum 6 characters long)</td>
                </tr>
                <tr>
                    <td>Password: </td>
                    <td><input type="password" name="passPassword" />#160;(minimum 8 characters long)</td>
                </tr>
                <tr>
                    <td>Confirm Password: </td>
                    <td><input type="password" name="passConfirmPassword" /></td>
                </tr>
                <tr>
                    <td><input type="submit" value="Create" /></td>
                </tr>
            </table>
        </form>
        <p>v1.5</p>
    </body>

</html>
The only problem is that the validator of W3 won't validate it as Strict XHTML 1.0, because the name attribute is deprecated. I know that but what can I do to fix this bug and let is be a Strict XHTML 1.0 document.

Extra:

The JavaScript I used for the form validation:
Code:
function validate(form) {

    var formFilled = true;

    var username = document.formCreateAccount.textUsername.value;
    var password = document.formCreateAccount.passPassword.value;
    var confirmedPassword = document.formCreateAccount.passConfirmPassword.value;

    if(username.length < 6){
        alert("Your username must be at least 6 charcaters long!");
        document.formCreateAccount.textUsername.value = "";
        formFilled = false;
    }
    if(password.length < 8){
        alert("Your password must be at least 8 characters long!");
        document.formCreateAccount.passPassword.value = "";
        document.formCreateAccount.passConfirmPassword.value = "";
        formFilled = false;
    }
    if(password !== confirmedPassword){
        alert("Your password doen't match the confirmed one!");
        document.formCreateAccount.passPassword.value = "";
        document.formCreateAccount.passConfirmPassword.value = "";
        formFilled = false;
    }
    return formFilled;
}

The PHP file which process the value filled in on the form

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
    <head>
        <title>Submit to database</title>
        <link rel="stylesheet" type="text/css" href="jsOne.css" />
    </head>
    <body>
        <?php
            $username = $_POST['textUsername'];
            $password = $_POST['passPassword'];
            echo "Your username is: ".$username."<br />";
            echo "Your password is: ".$password."<br />";
        ?>
    </body>
</html>
I would be very pleased if you can help me validating this document as Strict XHTML 1.0!

Thank you in advanced! Greetz Thijs from the Netherlands!

Reply With Quote
  #2 (permalink)  
Old August 26th, 2005, 01:36 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi Thijs,

You can use document.getElementById to get a reference to a form or to one of its controls. Then you can drop the name attribute from the form tag.

  var formFilled = true;
  var theForm = document.getElementById ('formCreateAccount')
  // Now you have a reference to the form. Use it to call sumbit() for example:
  //theForm.submit();

  '' Same works for text boxes:
  var username = document.getElementById('textUsername').value;
  // etc

I think you'll need to leave the name attribute on the form controls to make sure they are submitted to the server. That should be valid XHTML though.

Cheers,

Imar
Reply With Quote
  #3 (permalink)  
Old August 27th, 2005, 09:48 AM
Authorized User
 
Join Date: Aug 2005
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks a lot Imar! It works good and it validate Strict XHTML 1.0!

Greetz Thijsje!

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT for parsing XHTML Form shahbhat XSLT 6 August 26th, 2008 06:22 PM
Strict Javascript newbieboobers Javascript 1 July 28th, 2008 05:23 AM
Option Strict kevin777 VB.NET 2002/2003 Basics 2 October 10th, 2003 11:38 PM
XHTML Strict Frame Borders Alexpizzoferro HTML Code Clinic 4 September 21st, 2003 11:54 AM
no target attribute in XHTML strict Alexpizzoferro HTML Code Clinic 3 June 22nd, 2003 04:17 PM



All times are GMT -4. The time now is 08:20 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.