开发者

Hide textbox if data is available in table

I have a sign-up form, which of course shows up blank. When the user types in a couple of letters of the team captain, autocomplete displays available choices and fills in phone number and email address if they exist. What I am trying to do is hide the divs for the email address and phone number IF they already exist. If they don't exist, the user can fill in the textbox and the data will be written into the table.

Here is what I am trying to get to work:

    $(document).ready(function() {
        if ($("#capphone").text().length > 0) {
            $("#tm_info2")开发者_开发技巧.hide();
        };

        if ($("#capemail").text().length > 0) {
            $("#tm_info1").hide();
        };
    });

Am I headed in the right direction or totally out in left field? As always, thanks for the input!


There are a couple of issues with your code:

  • .text().length wont return anything, you need to go with .val().length as that returns the length of the VALUE of the input element.

  • The if tests you are running occur on $(document).ready. They really need to occur AFTER you click on an auto complete item as the input fields are only populated once an auto complete item is selected.

  • You really need a way of differentiating between the autocomplete filling in the field and a user manually filling in the field.

Without access to your autocomplete code i cannot 100% answer your question, but put the following in a function that is called when you click on an auto complete name:

 if ($("#capphone").val().length > 0) {
     $("#tm_info2").hide();
 };

 if ($("#capemail").val().length > 0) {
     $("#tm_info1").hide();
 };
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜