i need to write a code to validate password the user enters if he/she enters the right one then i need to display the image which suggests the password as right or in the either case i need to display the cross image...so how can i do that using java script????
You can use a regular expression to validate the password syntax. If you want to check whether the password is valid one or not then you have to use a server side etechnology and match against your database.
Do you wish to validate the password in Javascript? If you are using AJAX, you need to parse the response and set the image's src using javascript.
Well you will need to create a a hidden DIV or a 1x1 transparent pixel image in the page, on the form submit call your javascript function to validate the password. If the password is correct, then change the img src property of your 1x1 pixel to the image you want to show, if it is incorrect then change the img src property using javascript to a cross sign. Same approach you can take to manipulate the innerHTML property of a div to add/remove your image. Hope that helps, let me know if you need an example.
If you want to validate form input using javascript - you could use an external javascript library to validate form input like this jquery plugin - saves a lot of time than writing your own code. However bear in mind that javascript validation should not be your only form of validation. Perform a server sided check as well.
精彩评论