开发者

Signup page validation

I want to create simplest validation for my signup form. My signup form contains input fields with default values. It must check for values of the fields. If user doesn't change default value of the field the script must alert about it.

How can I do it? My signup form looks like开发者_StackOverflow that: http://pastie.org/2369498 and reg.js: http://pastie.org/2369500


You've tagged your question with jQuery, so I'll give you a jQuery answer. You can get the value of a field using the val method:

$("#someField").val();

You can then compare the current value of the field with your default value, and perform some action if that's the case:

if($("#someField").val() === "Default") {
    $("#errorMessage").text("You must enter someField.");
}

You could also look into the jQuery validation plugin.

Update (based on comments)

You can get the value of the selected radio button the same way as shown above, with the val method:

var selectedType = $("input[name=type]").val();
switch(selectedType) {
    case "1":
        //Validate required fields as shown above
        break;
    case "2":
        //Validate next lot of fields
        break;
    //Continue with as many sections as you have.
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜