Sunday 15 April 2012

javascript - Validate texbox by comparing select options to textbox contents -



javascript - Validate texbox by comparing select options to textbox contents -

so have add together contacts page need popup error message or mark input invalid if effort come in existing contact name.

there select populated options. not sure how compare alternative values of select texbox....

i need check text in contact textbox not exist in of select options.

<asp:dropdownlist id="contactsdropdown" runat="server" autopostback="true"onselectedindexchanged="oncontactchanged" </asp:dropdownlist> <asp:textbox id="contact" runat="server" textmode="singleline" />

firstly ,don't forget add together clientidmode="static" both contactsdropdown , contact controls ,so can select element jquery.more info here.

then can utilize simple condition:

var exists= $("#contactsdropdown option[value='"+ $("#contact").val()+"']").length > 0; if (exists) { alert("error - > exists!") //or } else{ //do else }

hope helps!

javascript jquery html asp.net

No comments:

Post a Comment