I want to check the length of input string and validate it.If its greater than length the show message beside the text box.I my case the length is 10
<div>
<input type="text" name="ref_code" id="ref_code" value="" onchange="checkCodeStatus()" size=18>
<div id="msg" style="margin-left: 15px;"></div>
</div>
<script type="text/javascript">
function checkCodeStatus(){
var ref_code = $("#ref_code").val();
$.ajax({
type:'post',
url:'<?php echo site_url('mypage/check_code/'); ?>',
data:{ref_code: ref_code},
success:function(msg){
if(msg.indexOf('value does exist') > -1)
$('#msg').html('<span style="color: green;">'+msg+"</span>");
else $('#msg').html('<sapn style="color:red;">Value does not exist</span>');
}
});
}
</script>