View Single Post
Old 2010-02-15, 09:46 PM   #5
HarryM
No offence Apu, but when they were handing out religions you must have been out taking a whizz
 
HarryM's Avatar
 
Join Date: Jan 2004
Location: Australia
Posts: 285
Send a message via ICQ to HarryM
That PHP code you posted is just priting the submit form, you can't validate input at this stage.

This would work though (on client side), I commented it so you can change it to suit.

Code:
<script type="text/javascript" >
    function validate() 
    {
        // Get submission form
        var submitForm = document.forms["submission_form"];
        
        // Number of input fields entered by user
        var count = 0;
        
        // Check the 3 elements for valid content
        for (var i = 1; i < 4; i++)
        {
            if (validateContentCount(submitForm.elements["elements[" + i + "]"])) 
            {
                count++;
            }
        }

        // Make sure one text area was entered by user
        if (count < 1) 
        {
            var errorMessage = document.createElement("p");
            var errorText = document.createTextNode("Error: Must specify content count.");
            errorMessage.appendChild(errorText);
            errorMessage.style.color = "#ff0000";
            submitForm.appendChild(errorMessage);
            return false;
        }
        else 
        {
            return true;
        }
    }

    function validateContentCount(element) 
    {
        // Check for at least one digit (\d)
        var intCheck = new RegExp(/\d+/);

        if (!intCheck.test(element.value)) 
        {
            return false;
        }
        else 
        {
            return true;
        }
    }
</script>
__________________
Click here to make huge $$$
HarryM is offline   Reply With Quote