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
Casino | Gaming, Cards, Gaming & Entertainment | Dr.MCD
ReplyDeleteDr.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