Alert box, if certain word is entered in text box.

Hi there,

I currently have a WordPress website,  which is using the WP-Job Manager plugin on the home page.

Everything is working as it should,  but not just learned that we cannot hire out of California.   I've taken out all the jobs we have for that, but we also have a sticky job which always appears at the top of the listings, regardless of what city, state, zip code is entered.
the sticky job location is just USA, and uses google api, so it will appear top of any location entered.

I just cannot hide it for California.

I was wondering if anything had similar problems or different solutions.   Maybe, if California was typed, a Javascript alert box appears, saying we don
t hire from California?  

Just at a loss as for how to fix this.  Any ideas?

<< Website >>
Jon ImmsWeb DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Zakaria AcharkiAnalyst DeveloperCommented:
Hi Jon, In which step you want to show up the alert? I mean when the user clicks "APPLY" or after the redirect in the job offer details?
Jon ImmsWeb DeveloperAuthor Commented:
Screenshot-2018-12-19-10.20.47.png
So in the first box, "Enter City, State or ZipCode".  Ideally, if someone enters the word cali, ca, or California, then the alert pops up .. something like, "we currently do not hire from the state of California. "
Zakaria AcharkiAnalyst DeveloperCommented:
So it could be something like :

$(function() {
  $('body').on('blur', '#search_location', function() {
    var excluded_cities = ['ca', 'cali', 'california'];

    if ($.inArray($(this).val().toLowerCase(), excluded_cities) != -1) {
      alert("we currently do not hire from the state of California.");
    }
  });
});

Open in new window


The blur event will be triggered when the user loses the focus of the search_location input, and it will check if the value entered matches one of the values of excluded_cities , so if yes it will alert the message else it will continue normally.
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Jon ImmsWeb DeveloperAuthor Commented:
Hi Zakaria,

Thanks for the snippet.  I did try this,  put the code in a file /wp-content/themes/enfold/js/cali.js

But it's not doing anything when i type in cali etc.
Zakaria AcharkiAnalyst DeveloperCommented:
You're welcome sir,

You need to make sure the code is accessible, clear the cache of your browser and try to add an alert just before the event to make sure it will be shown when the page is fully loaded.
Jon ImmsWeb DeveloperAuthor Commented:
Hi Zak, ok it's close. when I type in ai get the alert, but if after I've clicked ok, and then select a freight type, it will bring up the listings.  Is it possible to block selecting a fright type as well if California criteria are entered?
Zakaria AcharkiAnalyst DeveloperCommented:
Good job Jon, Yes we can disable it until the user changes the excluded city like :

$(function() {
  $('body').on('blur', '#search_location', function() {
    var excluded_cities = ['ca', 'cali', 'california'];

    if ($.inArray($(this).val().toLowerCase(), excluded_cities) != -1) {
      alert("we currently do not hire from the state of California.");
      $('.job-manager-filter').attr('disabled', 'disabled');
    }else{
      $('.job-manager-filter').removeAttr('disabled', 'disabled');
    }
  });
});

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jon ImmsWeb DeveloperAuthor Commented:
Hey Zak,   Almost there,  getting a few errors, wonded if you could help.

So i modified your code, so it takes out the checkboxes.  It's working in my chrome, but other browsers i'm getting

undefined is not a function (near '...$...')

Open in new window

<script>
	$(function() {
  $('body').on('blur', '#search_location', function() {
    var excluded_cities = ['ca', 'cali', 'california'];

    if ($.inArray($(this).val().toLowerCase(), excluded_cities) != -1) {
      alert("we currently do not hire from the state of California.");
      $('#job_type_dry-van').attr('disabled', 'disabled');
      $('#job_type_refrigerated').attr('disabled', 'disabled');
      $('#job_type_flat-bed').attr('disabled', 'disabled');
    }else{
      $('#job_type_dry-van').removeAttr('disabled', 'disabled');
      $('#job_type_refrigerated').removeAttr('disabled', 'disabled');
      $('#job_type_flat-bed').removeAttr('disabled', 'disabled');
    }
  });
});
	</script>

Open in new window

lenamtlCommented:
Hi,

I would not use that method, to my opinion this is not user friendly, plus any user can disable the popup by clicking the checkbox that will prevent to show it again..

Also let say you want to block other states in future this will become a huge JS for nothing and JS can easily bypass by any browser console..

This take a second to remove the disable attribute...

Instead why don't you display a select drop down list with only the states that are allowed?
and have a different field for city based on the state and another one for zip code

This will also shorten your MySQL query and better performance.

PS I do work on a trucking apps too :)
Zakaria AcharkiAnalyst DeveloperCommented:
undefined is not a function (near '...$...')

Hi Jon, Please show me the full error, you could take a screenshot that may be helpful to detect the source of the error.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Google

From novice to tech pro — start learning today.