简体   繁体   English

即使数据值不正确,也无法显示正确的按钮

[英]can't show correct button even when data value is incorrect

  • I have an interface which check for quality attributes for a particular production batch. 我有一个界面,检查特定生产批次的质量属性。
  • I was able to get data from the back-end and shows in the frond-end. 我能够从后端获取数据并在前端显示。
  • but couldn't implemented the what I wanted with the reject and accept submit button. 但无法使用拒绝接受提交按钮实现我想要的。
  • firstly, when I enter some value within the range, value field input text becomes green and shows the "send to finish stock" button. 首先,当我在范围内输入一些值时, 字段输入文本变为绿色并显示“发送到完成库存”按钮。 instead what I want is display the "reject the batch" button. 而我想要的是显示“拒绝批次”按钮。 because other text inputs are not filled at yet. 因为尚未填写其他文本输入。

在此输入图像描述

  • secondly, when I enter some non-range value in value text input field ,It shows the "reject the batch" button. 其次,当我在值文本输入字段中输入一些非范围值时,它显示“拒绝批处理”按钮。 which is what I want. 这就是我想要的。 在此输入图像描述

  • problem is, I can't figure it, how to show the "reject batch button" when any one of the value text input field becomes red . 问题是,我无法弄清楚,当任何一个值文本输入字段变为红色时,如何显示“拒绝批处理按钮”。

  • when the all value text input field becomes green , I want to show the "send to finish stock" button. 当所有值文本输入字段变为绿色时 ,我想显示“发送到完成库存”按钮。
  • problem is, when I changes a particular value text input field , accordingly the reject or send to stock button shows. 问题是,当我更改特定值文本输入字段时 ,相应地拒绝发送到库存按钮显示。
  • ex:- first enter incorrect value, it should shows "reject the batch" button, which is what I want. 例如: - 首先输入不正确的值,它应显示“拒绝批次”按钮,这就是我想要的。
  • secondly, I enter correct value, it shows "send to stock" button, which is not what I want, and should display "reject the batch" button. 其次,我输入正确的值,它显示“发送到库存”按钮,这不是我想要的,并应显示“拒绝批次”按钮。
  • if there any red input text fields, I want to show "reject the batch" button, instead of "send to stock" button, so this is where I'm getting stuck how to implement this. 如果有任何红色输入文本字段,我想显示“拒绝批处理”按钮,而不是“发送到库存”按钮,所以这是我遇到如何实现这一点。
    hopefully this makes sense 希望这是有道理的

在此输入图像描述


this is my html markup 这是我的HTML标记

 <div class="text-center"> <button type="submit" class="btn btn-success btn-sm nodisp" data-toggle="tooltip" id="acceptbtn">send to finish stock</button> <button type="submit" class="btn btn-danger btn-sm nodisp" data-toggle="tooltip" id="rejectbtn">reject the batch</button> </div> 


this is my php code which display the form interface 这是我显示表单界面的php代码

 <?php $pro_item_id = $_GET['proitem']; include_once('../backend/ProductQCAttribute.php'); $pro_qc_attr = new ProductQCAttribute(); $all_qc_attr = $pro_qc_attr->get_all_qc_attributes_by_product_item_id($pro_item_id); $row = 0; foreach ($all_qc_attr as $single_qc_attrb) { echo ("<tr>" . "<td>" . "<input type='hidden' name='qc_attrb_id[]' id='qc_attrib_id_$row' class='form-control' value='$single_qc_attrb->pro_qc_attr_id' >". $single_qc_attrb->pro_qc_attr_name ."</td>" . "<td>" . "<input type='text' name='qc_value[]' id='qc_value_$row' class='form-control check-range' onchange='checkValue($row,$single_qc_attrb->pro_qc_attr_low_margin,$single_qc_attrb->pro_qc_attr_high_margin)' >" ."</td>" . "<td>" . "<input type='text' name='low_margin[]' id='low_margin_$row' class='form-control' value='$single_qc_attrb->pro_qc_attr_low_margin' readonly >" ."</td>" . "<td>" . "<input type='text' name='high_margin[]' id='high_margin_$row' class='form-control' value='$single_qc_attrb->pro_qc_attr_high_margin' readonly >" ."</td>". "</tr>"); $row++; } ?> 


this is the corresponding JavaScript code which check for those input values and display the "reject the batch" or "send to stock" button 这是相应的JavaScript代码,用于检查这些输入值并显示“拒绝批处理”或“发送到库存”按钮

  // change the color of input fields based on input user provide // function working correclty function checkValue(row,lowMargin,highMargin) { if($("#qc_value_"+row).val() >= lowMargin && $("#qc_value_"+row).val() <= highMargin) { $("#qc_value_"+row).addClass('green-check'); $("#qc_value_"+row).removeClass('red-reject'); // red-reject class I defined in the css file..its ok } else { $("#qc_value_"+row).addClass('red-reject'); $("#qc_value_"+row).removeClass('green-check'); } check_green(row); // calling to this might be in the wrong place, I tried different places but didn't work it out. } // check weather all input fields are green, then show the accept button // function working correctly function check_green(row) { if($("#qc_value_"+row).hasClass('green-check')) { // green-check class I defined in the css file..its ok $("#status").val('pass'); $("#acceptbtn").removeClass('nodisp'); // nodisp class I defined in the css file..its ok $("#rejectbtn").addClass('nodisp'); } else { $("#status").val('fail'); $("#rejectbtn").removeClass('nodisp'); $("#acceptbtn").addClass('nodisp'); } } 


I tried and can't figure out what I'm doing here wrong or what is missing in my code..if someone can give me insight how to figure this out It would be appreciated.. thanks. 我尝试过,无法弄清楚我在这里做错了什么或者我的代码中缺少什么......如果有人能给我一些洞察力如何解决这个问题我将不胜感激。谢谢。

You can check if any control in your form has the red-reject class and show your buttons accordingly. 您可以检查表单中的任何控件是否具有red-reject类并相应地显示您的按钮。

A jQuery collection has a length property that you can use. jQuery集合有一个可以使用的length属性。

I changed your markup a bit to use event listeners instead of onChange , it decouples the markup from the logic making it easier to maintain. 我稍微改变了你的标记以使用事件监听器而不是onChange ,它将标记与逻辑分离,使其更易于维护。

 // Execute whenever a user input changes $('.check-range').on('change', function() { // Cache the jquery object $this = $(this); currentValue = parseFloat($this.val()); // Find corresponding range values lowMargin = parseFloat($this.closest('tr').find('[id^="low_margin"]').val()); highMargin = parseFloat($this.closest('tr').find('[id^="high_margin"]').val()); // Check bounds and add classes if ((currentValue >= lowMargin) && (currentValue <= highMargin)) { $this.addClass('green-check'); $this.removeClass('red-reject'); } else { $this.addClass('red-reject'); $this.removeClass('green-check'); } // Update button status // 0 is falsey, any other value is truthy if ($('.check-range.red-reject').length) { // There are invalid parameters $("#rejectbtn").removeClass('nodisp'); $("#acceptbtn").addClass('nodisp'); } else { $("#acceptbtn").removeClass('nodisp'); $("#rejectbtn").addClass('nodisp'); } }) 
 .green-check { background-color: green; } .red-reject { background-color: red; } .nodisp { display: none; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <table> <tr> <td><input type='hidden' name='qc_attrb_id[]' id='qc_attrib_id_1' class='form-control' value='2'> Attr name </td> <td><input type='text' name='qc_value[]' id='qc_value_1' class='form-control check-range'></td> <td><input type='text' name='low_margin[]' id='low_margin_1' class='form-control' value='15' readonly></td> <td><input type='text' name='high_margin[]' id='high_margin_1' class='form-control' value='20' readonly></td> </tr> <tr> <td><input type='hidden' name='qc_attrb_id[]' id='qc_attrib_id_2' class='form-control' value='2'> Attr name </td> <td><input type='text' name='qc_value[]' id='qc_value_2' class='form-control check-range'></td> <td><input type='text' name='low_margin[]' id='low_margin_2' class='form-control' value='5' readonly></td> <td><input type='text' name='high_margin[]' id='high_margin_2' class='form-control' value='25' readonly></td> </tr> </table> <div class="text-center"> <button type="submit" class="btn btn-success btn-sm nodisp" data-toggle="tooltip" id="acceptbtn">send to finish stock</button> <button type="submit" class="btn btn-danger btn-sm nodisp" data-toggle="tooltip" id="rejectbtn">reject the batch</button> </div> 

暂无
暂无

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

相关问题 如果值正确,将无法显示警告 - Can't get alert to not show if value is correct 为什么当选中此复选框时它将显示不正确的数据值? - Why when checked checkbox it's will show incorrect data value? 即使详细信息正确,Ajax登录也会返回错误的详细信息 - Ajax login returning incorrect details even when details are correct 为什么当用户单击按钮时我无法显示我想要的数据 - why i can't show data i want when user clicks on button 尝试将预期值与错误值进行比较时出现脚本错误。 如果我将它与正确的值进行比较,它将给出正确的结果数据 - I am getting script Error when try to compare expected value with incorrect value. if I compare it with correct value it will give correct result data 使用jQuery单击按钮时无法显示输入文本 - Can't show text from an input when click button with jQuery 选中单选按钮时我无法隐藏/显示文本框 - I Can't Hide/Show Textbox when radio button is checked 验证电子邮件javascript:当电子邮件不正确时显示叉号/在电子邮件正确时显示刻度线? - validate email javascript: show cross when email incorrect/show tick when email correct? 即使html将其显示为正确值,也向Javascript函数发送了不正确的值 - Javascript function being sent incorrect value even though the html shows it as being correct Highcharts - 显示至少5条水平网格线,即使值不变 - Highcharts - show at least 5 horizontal grid lines, even when value doesn't change
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM