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;
}

Recommended Answers

All 6 Replies

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/

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

I took a second look, I don't see any missing "}".

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

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.

Working! thanks all.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.