Check if Text is Selected in Input Box or Text Area in JavaScript

<html>
<body>
<input type="text" id="test" value="Some text">
<input type="button" onmousedown="alert(isTextSelected(document.getElementById('test')));" value="Selected?">
<script type="text/javascript">
function isTextSelected(input) {
    var selecttxt = '';
    if (window.getSelection) {
        selecttxt = window.getSelection();
    } else if (document.getSelection) {
        selecttxt = document.getSelection();
    } else if (document.selection) {
        selecttxt = document.selection.createRange().text;
    }

    if (selecttxt == '') {
        return false;
    }
    return true;

}‚Äč
</script>
</body>
</html>