Click here to Skip to main content
15,942,144 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi ,sir
how to display selected dropdown value in textbox using jquery ?
for example

JavaScript
$("#Button1").click(function () {
      $("body").append('<input type="text" name="mytextbox" id=TextboxId></input>');

      $("#TextboxId").attr('maxlength','2');


       //  $("input").css({ left: +e.pageX, top: +e.pageY });
      $('input').focus();
          $('input').appendTo("body");

      // var jTextBox = jQuery('<input type="text" name="mytextbox">');
      var data = {
          'value': '1', 'value2': '2', 'value3': '3',
          'value4': '4'
      };
      var s = $('<select />');
      for (var val in data) {
          $('<option />', { value: val, text: data[val] }).appendTo(s);
      }
      s.appendTo('body');

      $(function () {
          $('#TextboxId').keydown(function (e) {
              if (e.shiftKey || e.ctrlKey || e.altKey) {
                  e.preventDefault();
              } else {
                  var key = e.keyCode;
                  if (!((key == 8) || (key == 46) || (key >= 35 && key <= 40) || (key >= 48 && key <= 57) || (key >= 96 && key <= 105))) {
                      e.preventDefault();
                  }
              }
          var ddl = $(this).attr('value');

          });
      });
});
});
Posted
v2

1 solution

try like below
JavaScript
$(document).ready(function()
{
$('#textBoxId').val($("#YourDropDownId option:selected").text());
});


Hope this helps
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900