jquery - How to display the error message -


when click button want validate fields , if there errors, want show user error message on top.

i validating not able show error message. problem?.

$(document).on('click', '#button', function() {    var firstname = $('#fname').val();    alert(firstname);    var lastname = $('#lname').val();        if (firstname.val() == '') {      $("#error").append("please enter first name");    } else if (lastname.val() == '') {      $("#error").append("please enter last name");    }  });
<div data-role="content" style="padding: 15px;margin-top:21px">    <p id="error"></p>    <label for="text">first name:</label>    <input type="text" name="text" id="fname">    <label for="text">last name:</label>    <input type="text" name="text" id="lname">    <a href="" data-role="button" id="button" onclick="dtlssubmit()">submit</a>  </div>

$(document).on('click', '#button', function() {    var firstname = $('#fname').val();    var lastname = $('#lname').val();        if (firstname == '') {//remove .val()      $("#fnameerror").show();    } else if (lastname == '') {//remove .val()      $("#lnameerror").show();    }  });
.error{        display:none    }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <div data-role="content" style="padding: 15px;margin-top:21px">    <p id="error"></p>    <span id='fnameerror' class='error'>please eneter first name</span>    <label for="text">first name:</label>    <input type="text" name="text" id="fname">    <span id='lnameerror' class='error'>please eneter last name</span>    <label for="text">last name:</label>    <input type="text" name="text" id="lname">    <a href="#" data-role="button" id="button" ">submit</a>  </div>

add span error message show if match condition


Comments

  1. Casino | Gaming, Cards, Gaming & Entertainment | Dr.MCD
    Dr.MCD provides you with a casino card selection that is perfect for your play. 서귀포 출장샵 This means you can play 광주광역 출장마사지 all 속초 출장안마 the slots and many video 천안 출장안마 slots at 양산 출장마사지 any

    ReplyDelete

Post a Comment

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -