html代码如下:
<tr>
<td>i</td>
<td colspan="3">Temperature Of Warming Bin/Chute(140F -150F/60C - 65C)</td>
<td>1</td>
<td>
class="col-sm-12">
<input required type="number" class="form-control" name="b_1_1" id="b_1_1" min="0" max="1">
</div>
</td>
</tr>
我在html中的评论框是:
<div class="form-group">
<textarea class="form-control" placeholder="Comments" name="Comments" id="Comments" rows="6"></textarea></div>
如果在继续下一个表单之前,如果用户输入在下面的textarea中为“0”而不是“1”,则强制用户给出有效理由。我总共有5种表格。
答案 0 :(得分:0)
您应该使用一些Javascript库来验证用户输入。您可以使用jQuery实现此目的,例如:
$('#IdOfYourForm').on('submit', function(e) { // trigger this when the form is submitted
e.preventDefault();// stop the form from submitting
var min = $('#b_1_1').attr('min'); // min value of the element's attribute min = "0"
var max = $('#b_1_1').attr('max'); // max value of the element's attribute max = "1"
var userInput = $('#b_1_1').val();
if (userInput == min) { // if the user entered a value equals to the value in the min ="0" attribute then ask reason
// alert him with a pop-up or something to ask for the reason.
} else if (userInput == max) { // if the user input = maximum
$(this).submit();// submit the form and move on to the next form
} else { // if the user inputs something that is neither 1 or 0 like 5 for example
// alert an error
}
});
希望这有帮助。
答案 1 :(得分:0)
我不确定你是怎么想这样做的: 如果你想用php:
<?php
if(isset($_POST['b_1_1']) && $_POST['b_1_1'] == 0){
echo '<div class="form-group"><textarea class="form-control" placeholder="Comments" name="Comments" id="Comments" rows="6"></textarea></div>';
}
如果你想用JS做这件事:
document.querySelector('#Comments').style.display = 'none';
document.querySelector('#b_1_1').addEventListener("change", function(){
if(this.value == 0) document.querySelector('#Comments').style.display = 'block';
});