hello
i have a form for registering the user and i use java script for client side check that the field is filled or not the problem is that when user not fill the first name and press register button it will show client side message that the first name must be filled and after the message it will go on next page and save the data into database. i want that the next page could not open if any field is empty please tell me the solution

waiting for your reply

Recommended Answers

All 4 Replies

Member Avatar for stbuchok

If you have "return false;" for the onclick event it cancels the postback. The following is a quick example.

function validate(){
    var blnIsValid = true;

    if(field.length <= 0){
        blnIsValid = false;
    }

    return blnIsValid;
}

<input type="button" id="btnSave" value="Save" onclick="return validate();" />

i have done this but the problem not solved

i have all the client side checks with the help of java script

when i click register button it show the message that first name is not filled and after that message it go on register.php page and enter the data into database (mySQL)

i say that if any message show in client side, the page should not go forward to register.php and don't save data into data base

waiting for your reply

Member Avatar for stbuchok

Please show your code for the click event and the validation function. It sounds like you are still getting a postback which wouldn't be happening if you had return false for the click event.

On a side-note: i don't think depending on client-side checks is a good idea.
It's far too easy for hackers to misuse, so i would advise to develop a server-side check first.
Once that is working right, you can use javscript, so the user doesn't have to click a link to see what they did wrong

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.