-1

I am working with PHP. When a user selects any item from a combo box, the corresponding item will display in the second combo box. I need to store this second combo box value into the textbox for further use.

  <script type="text/javascript" src="jquery.min.js"></script>
        <script type="text/javascript">
            $(function(){
                $('#combo').change(function(){
                    console.log($(this));
                    $.get( "abc.php" , { option : $(this).val() } , function ( data ) {
                        $ ( '#comboB' ) . html ( data ) ;
                    } ) ;
                });
            });
        </script>
    </head>
    <body>

                <form>
                    <select name="combo" id="combo">
                        <option value="">-- Select</option>
                        <option value="1"> Personnel</option>
                        <option value="2"> Area Layout</option>
                          <option value="3">Conference Rooms</option>
                            <option value="4"> Small Office</option>
                             </select>

now abc.php
<?php
    $Options = Array ( 
        1 => Array ( 
        '--',
            '15 x 20 (300 sq. ft.)' ,
            '15’ x 15’ (225 sq. ft.)',
            ' 10’ x 15’ (150 sq. ft.)',
            '12’ x 10’ (120 sq. ft.)'
        ) , 
        2 => Array ( 
            '10’ x 10’ (100 sq. ft.)' ,
            ' 8’ x 6’ (48 sq. ft.)',
            '5’ x 5’ (25 sq. ft.)'
        ) ,
         3 => Array ( 
            '15’ x 25’ (375 sq. ft.)' ,
            '15’ x 20’ (300 sq. ft.)',
            '15’ x 15’ (225 sq. ft.)'
        ) ,
         4 => Array ( 
            '8’ x 8’ (64 sq. ft.)' ,
            '8’ x 6’ (48 sq. ft.)',
            '6’ x 6’ (36 sq. ft.)',
            '4’ x 6’ (24 sq. ft.)'
        ) 
    ) ; 

    forEach ( $Options [ $_GET [ 'option' ] ] as $Item ) {
        printf ( '<option value="%s">%s</option>' , $Item , $Item ) ;
    }
    ?>
Monolo
  • 18,205
  • 17
  • 69
  • 103
malika
  • 1
  • 4

1 Answers1

0

A javascript code like:

$('#comboB').change(function(){ $('#textbox').val($(this).val()); });

Will do the trick

EDIT example on how to modify the HTML

<script type="text/javascript" src="jquery.min.js"></script>
        <script type="text/javascript">
            $(function(){
                $('#combo').change(function(){
                    console.log($(this));
                    $.get( "abc.php" , { option : $(this).val() } , function ( data ) {
                        $ ( '#comboB' ) . html ( data ) ;
                    } ) ;
                });
                $('#comboB').change(function(){ $('#textboxB').val($(this).val()); });
            });
        </script>
    </head>
    <body>

                <form>
                    <select name="combo" id="combo">
                        <option value="">-- Select</option>
                        <option value="1"> Personnel</option>
                        <option value="2"> Area Layout</option>
                          <option value="3">Conference Rooms</option>
                            <option value="4"> Small Office</option>
                             </select>
    </form>
    <select id="comboB"></select>
    <input type="textbox" id="textboxB" value="" />
Mangiucugna
  • 1,732
  • 1
  • 14
  • 23
  • where i put this code i understand the loctation to put this kindly help me i need it for further computation second combox here which disply the data when user selcted any option from first combo box – malika May 05 '13 at 10:08
  • Put this code just after the _$('#combo').change(function(){...});_ – Mangiucugna May 05 '13 at 14:44
  • what about in textbox ,need to pass any id – malika May 05 '13 at 15:30
  • sir can u exatcly place it in the code n paste it here plz i have submission of this module tomorrow – malika May 05 '13 at 15:49
  • i need another help kindly see my this question also http://stackoverflow.com/questions/16387128/roundoff-number-upto-two-decimal-places – malika May 05 '13 at 19:13
  • I will see the question, meanwhile can you set my answer as the corre t answer and upvote also? Thanks – Mangiucugna May 05 '13 at 21:30