如何显示结果在不同的文本框上单击组合框在php

How to display result in different textbox on clickng the combo box in php

本文关键字:文本 php 组合 单击 何显示 显示 结果      更新时间:2023-09-26

如果从组合框中选择值,则在文本框中显示值。我需要在文本框中进一步使用这些值。我不知道如何在我的三个结果文本框中一键显示结果。

$options = array(
        '0' => array(
            'title' => '-- Select',
            'value1' => '',
            'value2' => '',     
        ),
        '1' => array(
            'title' => 'A',
            'value1' => '300',
            'value2' => '600',
        ),
        '2' => array(
            'title' => 'B',
            'value1' => '1800',
            'value2' => '900',          
        ),
    );
    if (isset($_GET['option']) && isset($options[$_GET['option']])) {
        echo json_encode($options[$_GET['option']]);
        exit;
    }

?>
<select name="combo" id="combo" onchange="getText66()" onblur="getText661()">
<?php
    foreach($options as $key_value => $option) {
        printf('<option value="%s">%s</option>', $key_value, $option['title']);
    }
?>

编码从文本框中选择值并显示在文本框中

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<script type="text/javascript">
    $(function(){
        $('#combo').change(function(){
            $.getJSON("?", {
                option : $(this).val()
            }, function (data) {
                $('#textboxB').val(data.value1);
                $('#textboxD').val(data.value1);
                $('#textboxE').val(data.value1);
                $('#textboxC').val(data.value2);
            });
        });
    });
</script>

对从文本框

获得的值执行一些计算的编码
<script>
 function getText66(){
      var in32=document.getElementById('textboxB').value;
      var in332=document.getElementById('in33').value;
      var in3332=document.getElementById('in333').value;
      var in134=(parseFloat(in32)*parseFloat(in332))+parseFloat(in3332); 
      document.getElementById('in134').value=in134.toFixed(2);
   }
    function getText661(){
      var in321=document.getElementById('textboxD').value;
      var in3321=document.getElementById('in331').value;
      var in33321=document.getElementById('in3331').value;
      var in1341=(parseFloat(in321)*parseFloat(in3321))-parseFloat(in33321); 
      document.getElementById('in1341').value=in1341.toFixed(2);
   }
    function getText662(){
      var in322=document.getElementById('textboxE').value;
      var in3322=document.getElementById('in332').value;
      var in33322=document.getElementById('in3332').value;
      var in1342=(parseFloat(in322)*parseFloat(in3322))-parseFloat(in33322); 
      document.getElementById('in1342').value=in1342.toFixed(2);
   }
   </script>
   <?php echo "winter" ?>
<input type="text" name="text1" value="0.89" id="in33" />
<input type="text" name="text2" value="29"  id="in333"/>
<input type="text" name="text3"  id="in134"/>
   <?php echo "Summer" ?>
<input type="text" name="text11" value="0.92" id="in331" />
<input type="text" name="text22" value=" 24.3 "  id="in3331"/>
<input type="text" name="text33"  id="in1341"/>
   <?php echo "Autumun" ?>
<input type="text" name="text111" value="0.98" id="in332" />
<input type="text" name="text222" value="2.3 "  id="in3332"/>
<input type="text" name="text333"  id="in1342"/>
</form>

我的问题是它只在id="in134"的文本框中显示结果。我需要显示结果在所有三个文本框id="in1341"id="in1342"上一键从组合框。它是如何可能的。请帮助我

快速和肮脏的代码

改变onchange功能:

<select name="combo" id="combo" onchange="NewFunction()" onblur="getText661()">
function NewFunction() {
     getText66();
     getText661();
     getText662();
}

这是因为您只在组合框中调用getText66()

代替

<select name="combo" id="combo" onchange="getText66()" onblur="getText661()">

<select name="combo" id="combo" onchange="getText66();getText661();getText662();" onblur="getText661()">