php - how to pass value from dynamic combo box into textbox? -
i working php. when user selects item combo box, corresponding item display in second combo box. need store second combo box value textbox 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> 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' ] ] $item ) { printf ( '<option value="%s">%s</option>' , $item , $item ) ; } ?>
a javascript code like:
$('#combob').change(function(){ $('#textbox').val($(this).val()); });
will trick
edit example on how modify 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="" />
Comments
Post a Comment