0

I have a dropdownlist with options and the last option is Other. If the user selects Other I have to make a text box visible.

I did it using asp.net and made the autopostback=true for ddlchanged event. When I follow this when ever the user selects other the page flickers and going to the top.

somebody told me that I can use jquery to do it with out loading the page again. can you tell me how? Also it should also check the required field validation.

2 Answers 2

3

Using jquery it will looks like:

$('#dropdown').change(function() {
   if ($(this).val() == 'Other')
    {
      $('#textbox').show();
    }
    else
    {
      $('#textbox').hide();
    }

});

Code: http://jsfiddle.net/8Ct5r/

Sign up to request clarification or add additional context in comments.

3 Comments

<script type="text/javascript"> $(document).ready(function () { $('#ddlColl').change(function () { if ($(this).val() == 'Other') { // $('#txtOther').show(); $('#txtOther').css('display', 'inline'); } else { // $('#txtOther').hide(); $('#txtOther').css('display', 'block'); } }); }); </script>
<asp:TextBox runat="server" ID="txtOther" style="display:none;" > </asp:TextBox>
What it should do? :) The only thing I noticed that this is server controls and in javascript ID of the control can be different, like ctrl01_txtOther, etc...
0
 $('#dropdownID').change(function () {
        var dropdownValue = $('#dropdownID').val();

        if (dropdownValue == 71) {
            $('#TextboxID').show();
        }
        else {
            $('#TextboxID').hide();
        }
    })

1 Comment

While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value.

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.