1
0
-1

Hi 

im having hard time with assigning the value of a selectbox to a textbox.

my select box is called Progress, which have options Stage 1, stage 2 etc.

each stage has a value assigned stage 1 = 0, stage 2 = 10 so on.

and i would like to view the value on textbox called Completion so that use can see the progress numerically.

Also im trying to show the value in the text box when there is a selection made

i have tried this code,

<script type="text/javascript">
$('input[name="Progress"]).change( function(){
    var e = document.getElementById("Progress");
    var value=e.selectElement.options[e.selectedIndex].value;
    $('input[name="Completion"]').val(value);
});
</script>

and this

<script type="text/javascript">
$(window).load(function(){
	$(document).ready(function() {
		$("#Progress option").filter(function() {
			return $(this).val() == $("#Completion").val();
			}).attr('selected', true);
		$("#Progress").live("change", function() {
			$("#Completion").val($(this).find("option:selected").attr("value"));
			});
		});
	});
</script>

and various other scripts.

in the same form i have other custom html scripts that works for datetimepickers but this seems to not work for me

any help is really appreciated

Thank you

    CommentAdd your comment...

    1 answer

    1.  
      2
      1
      0

      Do try the following:

      <script type="text/javascript">
      $('[name$=SelectBox]').change(function() {
      	var mySelectedValueId = $(this).find(':selected').val();
      	$('[name$=SelectedValueId]').val(mySelectedValueId);
      
      	var mySelectedValueText = $(this).find(':selected').text();
      	$('[name$=SelectedValueText]').val(mySelectedValueText);
      });
      </script>
      1. Dumidu Roshan

        Thanks, it worked

        i updated the code as

        <script type="text/javascript">
        $('[name$=Progress]').change(function() {
        	var mySelectedValueId = $(this).find(':selected').val();
        	$('[name$=SelectedValueId]').val(mySelectedValueId);
        
        	var mySelectedValueText = $(this).find(':selected').text();
        	$('[name$=SelectedValueText]').val(mySelectedValueText);
        	$('input[name="Completion"]').val(mySelectedValueId);
        });
        </script>
      2. Dumidu Roshan

        i did not need the selected text so, 

        <script type="text/javascript">
        $('[name$=Progress]').change(function() {
        	var mySelectedValueId = $(this).find(':selected').val();
        	$('[name$=SelectedValueId]').val(mySelectedValueId);
        	$('input[name="Completion"]').val(mySelectedValueId);
        });
        </script>
      CommentAdd your comment...