whoami
whoami

Reputation: 123

Assign HTML.Textbox length base on use input

I have Html.DropdownList control, base on the dropdown selection I need to set the length of the text box.

Ex: I have different registration number information in drop down

StudentRegestrationID

StaffRegistrationID

GustID

When even ever I select StudentRegestrationID its set the (Html.Textbox) control maxLength to 8, else for other two I need to set max length as 5.

Here maxlength of the control must be decide by the dropdown selection value.

I need to implement it JQuery any code help are appreciated.

Upvotes: 1

Views: 32

Answers (1)

Rino Raj
Rino Raj

Reputation: 6264

Please try this

$(document).ready(function(){
    $("select").change(function(){
        $('input').attr('maxlength',$(this).val());
    });
});

DEMO

Upvotes: 2

Related Questions