I am trying to use the following to change the value of 5 text boxes each time one of the 5 dropdown menus is changed. For some reason its not working though. I just want to take the value from the dropdown and put it into the text box, I dont need any other info such as the data between and , just the value, im not sure why its not working though :-S . The value from the dropdown will be a number string, such as 458766958

    <script>
    $('#stock1').change(function() {
        $('#stock1T').val($('#stock1 option:selected').data('value'));
    })

    $('#stock2').change(function() {
        $('#stock2T').val($('#stock2 option:selected').data('value'));
    })

    $('#stock3').change(function() {
        $('#stock3T').val($('#stock3 option:selected').data('value'));
    })

    $('#stock4').change(function() {
        $('#stock4T').val($('#stock4 option:selected').data('value'));
    })

    $('#stock5').change(function() {
        $('#stock5T').val($('#stock5 option:selected').data('value'));
    })
    </script>
有帮助吗?

解决方案

instead of using data() ,try getting the selected value using val()

      $('#stock1').change(function() {
              $('#stock1T').val($('#stock1 option:selected').val());
         });
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top