0

i know this is very simple question but i am new on this so please help me. i want to display the error message on my contact_result div but the script is not working, i wrote the following code:

$("document").ready(function() {
$("#contact_submit").click(function() {
    var first_name = $("#first_name").val();
    var last_name = $("#last_name").val();
    var phone = $("#phone").val();
    var email = $("#email").val();
    var atpos = email.indexOf("@");
    var dotpos = email.lastIndexOf(".");
    var msg = "";

    if(first_name == "") {
        msg+= "First Name is required.<br />";
    }

    if(last_name == "") {
        msg+= "Last Name is required.<br />";
    }

    if(Phone == "") {
        msg+= "Phone Number is required.<br />";
    }

    if (email == "" || atpos < 1 || dotpos < atpos+2 || dotpos+2 > email.length) {
    msg+= "Please enter a valid Email address. <br />";
    }

    if(msg !== "") {
        $("#contact_result").html(msg).show();
    }else {
        // post valuses
    }
});
});

2 Answers 2

2

try

if(phone == "") {

not

if(Phone == "") {
Sign up to request clarification or add additional context in comments.

Comments

0

Notice the error:

var phone = $("#phone").val();

your variable is "phone",but you use "Phone",this is a error, Javascript identifiers are case-sensitive.

The error can't display in div, because it you use use it like

this:$("#contact_result").html(msg)" not "$("#contact_result").html(msg).show()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.