jQuery code
var ordertxt = $j("#ordertxt");
ordertxt.blur(function() {
$j.ajax({
url: '<?php echo Mage::getUrl('contato/index/verifica') ?>',
type: 'POST',
data:{"ordertxt" : ordertxt.val()},
success: function(data) {
console.log(data);
data = $j.parseJSON(data);
$j("#msg_pedido").text(data.ordertxt);
}
});
});
Input you'd like to leave red
<input style="height:25px; width:262px; display: block;" name="order" id="ordertxt" class="input-text required-entry" type="text" />
Where error appears
<p style="color: #ee001c; font-size: 0.9166em;" id="msg_pedido" name="msg_pedido"></p>
Sample Image
Solution:
varordertxt=$j("#ordertxt");
ordertxt.blur(function() {
$j.ajax({
url: '<?php echo Mage::getUrl('contato/index/verifica') ?>',
type: 'POST',
data:{"ordertxt" : ordertxt.val()},
success: function(data) {
console.log(data);
data = $j.parseJSON(data);
if (data['ordertxtx'] == true ) {
$j("#msg_pedido").hide(data.ordertxt);
$j("#ordertxt").css("border","1px solid #ddd");
} else {
$j("#msg_pedido").show(data.ordertxt);
$j("#msg_pedido").text(data.ordertxt);
$j("#ordertxt").css("border","1px solid red");
}
}
});
});