0

In the following code blocks I don't see any affect that my java scipt is having on my form. Any ideas? Thanks.

Form:

    if($row['password'] == $passwd)
    {
    echo "<html>";
    echo "<body>";
    echo "<script src='check.js'></script>";
    echo "<form id='form1' action='changepassword.php' method='post'>";
    echo "<table>";
    echo "<tr><td>";
    echo "New Password<center><input type='text' name='newpassword1'></td></tr></center>";
    echo "<tr><td>";
    echo "Re-Enter Password<center><input type='text' name='newpassword2'></td></tr></center>";
    echo "<tr><td><input type='submit' value='submit' onclick='return validate(this.form,6,8)'></td></tr>";
    echo "</table>";
    echo "</form>";
    echo "</body>";
    echo "</html>";
    }

Script:

function validate(form, minlength, maxlength) 
{
    var userInput = form.elements[0].value

if(userInput.length >= minlength && userInput.length <= maxlength)
{
    return true;
}
else
{
    alert("Please input between " + minlength + " and " + maxlength + " characters");
    return false;
}
3
Contributors
6
Replies
22
Views
4 Years
Discussion Span
Last Post by lewashby
0

If you look at your javascript, you are missig a closing brace "}" at the end. When I copy your code and run it, it works fine.

Keep in mind that with your script, you are only checking the first input element. You'd have to modify this to ensure that both input elements are filled out and you have to make sure that the user typed in the same information in both input fields.

Here is a working demo of your code. http://itg.somee.com/dw/dw-465310/

Edited by JorgeM

0

I did make sure that both fields were the same but I did that part with php. Thanks, I'll give this another try.

0
function validate(form, minlength, maxlength) 
{
    var userInput = form.elements[0].value

    if(userInput.length >= minlength && userInput.length <= maxlength)
    {
        return true;
    }
    else
    {
        alert("Please input between " + minlength + " and " + maxlength + " characters");
        return false;
    }
} <-- this is missing
0

I see that I didn't past it here on daniweb but the last "}" is in my script and it still isn't doing anything.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.