0

I have a textbox called txtMobile.text. It offers a list of items for a user to select from a auto suggestion box. This works great until a user goes back to the textbox after selecting the autosuggestion, they can change the text and it doesnt prevent them. Any ideas how i can only get the user to be able to only select items from the auto suggestion and not let them edit the selected text?

<script> 

                //var txtMobile
                var isItemSelected = false;

                //Handler for AutoCompleter OnClientItemSelected event
                function onItemSelected() {
                    isItemSelected = true;
                }

                //Handler for textbox blur event
                function checkItemSelected(txtMobile) {
                    if (!isItemSelected) {


                        alert("Please select item from the list only");

                        document.getElementById("form1").reset();
                        //txtMobile.focus();

                        

                    }
                }


    </script>
5
  • Why don't use the build in html select tag? Commented Oct 21, 2020 at 10:59
  • Hi John, I am afriad the data source for the list is from SQL and its a huge long list. So the Textbox auto suggestion picks up the first 2 characters of the text and suggests an entry based on that Commented Oct 21, 2020 at 12:53
  • You can give attribute ' readonly' to your textbox. Then users will not be able to modify the content. Commented Oct 21, 2020 at 13:24
  • Hello T.Shah, Thank you. I have tried that but it stops the user entering in the 1st two characters to allow a match. It would be great if i knew how to make the textbox ReadOnly after the user has selected an item from the suggestion list. Any deas? Commented Oct 21, 2020 at 13:48
  • stackoverflow.com/questions/1362153/… - This will help Commented Oct 21, 2020 at 14:01

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.