dimanche 27 novembre 2016

IF OR Function in jQuery on a PHP site

Can anyone tell me what's wrong and how to fix this bit of code...

I am trying to bring up a message and not go to the next page, if the #send_country box has either nothing in it or says "Send From..." (as its the placeholder).

This is the bit of code I am having issues with:

 if (country == '0' || country == "Send From...") {
                error = 1;
                jQuery('.msg').text("Please Select A Country.");
            }

I think I have an issue with the OR function as it works without the || country == "Send From...". Thanks

<script>
    jQuery(document).ready(function(){
        jQuery('.submit').click(function() {

            var error = 0;
            var country = jQuery('#send_country').val();
            var countrys = jQuery('#delv_country').val();
            var idsa = jQuery('.size').val();

            if (country == '0' || country == "Send From...") {
                error = 1;
                jQuery('.msg').text("Select A Country.");
            }
            if (countrys == '0') {
                error = 1;
                jQuery('.msg').text("Select A Country.");
            }

            if (error) {
                return false;
            } else {
                return true;
            }

        });

    });
    </script>

Aucun commentaire:

Enregistrer un commentaire