I have the following ajax/jquery script which passes data to my mysql query and checks if the value in my input field matches that which is in my data base. the function works fine, however i am trying to add an if statement to prevent the function running if the input field is blank?
I have tried the following which should cause the border of the input field to turn red and prevent any other function happening, but this doesn't work and my script has completely stop working all together. please can someone show me what i am doing wrong? Thanks in advance.
HTML:
<input type="text" id="promo" placeholder="Promotional Code" class="login_form2" /><div class="promo_check"></div>
Script:
<script type="text/javascript">
$(document).ready(function() {
$(document).on('click', '.promo_check', function() {
var a = document.forms["request"]["promo"].value;
if (a == null || a == "" null) {
if (a == null || a == "") { document.forms["request"]["promo"].style.borderColor = "#963634"; }
return false;
}else{
var promo = $("#promo").val();
$.ajax({
type: "POST",
url: "include/process_promo.php",
data: {data:promo},
success: function(data)
{
$(".form_error").show().html(data);
}
});
});
});
</script>