How to show the shortcut depending on whether there is a dropdown of options?
I have a dropdown that is populated with a Javascript function provided by an external company. It basically checks if the input is of a valid zip type and then returns the possible addresses in the dropdown.
I am stuck on how to then display a small message when the dropdown has some parameters i.e. some address was found and populated in select.
I've tried this:
$(function() {
function showmsg() {
if ($("#selectaddress").length > 1)
$('#buttonhint2').slideDown('normal');
}
$("#btnFind").click(showmsg)
});
But he doesn't do anything. I'm completely new to this, so I'm not sure if I'm even barking on the correct tree. Any help is greatly appreciated.
Well, you probably have to wait until this outer function has executed its code. I don't know anything about this function or where it runs, so I can't help you. If that gives you the ability to give it a callback function, just pass it the "showmsg" function that you have (and is written outside of the statement ready doc, as Jimmy mentioned).
If it ignores the parameter of the callback function, and you know that it fires on page load, you can delay your showmsg function for say 500ms or something. This might give enough time for the first script to run (but you'd like to play around with this before getting it right). If the first function uses AJAX to retrieve data, you might want to revisit that function, or simply modify this third party function (if the license allows) to add callback functionality.
You can install the script like this:
$(function() {
setTimeout(function() {
if ($("#selectaddress option").length > 0) {
$('#buttonhint2').slideDown('normal');
}
},500);
});
Also, don't do the thing that you need to check the number of options in the select box, not the number of select boxes you have on the page. And you have checked at least two options before this, script I provided at least 1 checks.
a source to share