简体   繁体   English

如何在PHP中单击组合框时在不同的文本框中显示结果

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

i display the values in textbox on selcting the values from the combox box. 从combox框中选择值时,我在文本框中显示值。 i need to used these values further that is in the textbox.i dont get how can i display the result on one click on combox in my three result textbox. 我需要进一步在文本框中使用这些值。我不知道如何在我的三个结果文本框中单击combox时显示结果。

$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']);
    }
?>

coding of selecting value from the textbox and display in the textbox 从文本框中选择值并在文本框中显示的编码

<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>

coding of performing some calcuations on the values get from the textbox 对值进行一些计算的编码是从文本框中获取的

<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>

My problem is that it only display result in the textbox of id="in134" . 我的问题是,它仅在id="in134"的文本框中显示结果。 i need to display the result in all three textbox id="in1341" and id="in1342" on one click from the combobox .how it be possible .kindly help me 我需要在组合框上单击一下,以在所有三个文本框id="in1341"id="in1342"显示结果。

Quick and dirty code 快速而肮脏的代码

Change onchange function: 更改onchange功能:

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

function NewFunction() {
     getText66();
     getText661();
     getText662();
}

That's because you only call getText66() in your combo box 那是因为您只在组合框中调用getText66()

replace 更换

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

by 通过

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

Protip: this is dirty. 提示:这很脏。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM