몇 가지 버튼이있는 간단한 HTML 양식이 있습니다. 어떤 도움을 받아 어떤 버튼을 클릭했는지에 따라 다른 액션을 처리하는 자바 스크립트를 구현했지만, POST
매개 변수로 클릭 한 버튼의 값을 표시하지 않는 것으로 나타났습니다.자바 스크립트 차단 값에서 제출 버튼
결과적으로 조건부로 분기해야하므로 작업 페이지에서 클릭 한 버튼을 알아야합니다. 내 자바 스크립트
<form role="form" action="index.php?action=updateItem" id="review" method="post">
<input type="hidden" name="itemID" value="CBE21852-FF46-5F43-8A59-C59AAE865F28">
<div class="checkbox">
<label class="checkbox"><input type="checkbox" name="ticked" value="ticked" id="ticked" required></label>
</div>
<p>Quantities are correct<br>Size and orienation is correct<br>
<hr>
<button type="submit" class="btn btn-default" name="buttonType" id="Revision" value="PDF-proof">Revision</button>
<button type="submit" class="btn btn-default" name="buttonType" id="Approved" value="Approved">Approved</button>
</form>
과 여기에 : 여기 내 HTML 양식의
Array
(
[action] => updateItem
[itemID] => CBE21852-FF46-5F43-8A59-C59AAE865F28
[ticked] => ticked
)
: 내가 볼 모두 다음은 index.php를 페이지의 양식 값을 확인
<script>
$(document).ready(function() {
$('#review button[type="submit"]').click(function(e){
e.preventDefault(); // this for prevent form from submit
if($(this).val() == "Approved"){ // check if third button was clicked
if($('#review #ticked').is(':checked')){ // check if checkbox is checked
$('#review').submit(); // submit form
}else{
alert("Please tick the checkbox before approving");
}
}else{ // any other button
$('#review').submit();
}
});
$("#rejectReason").validate({
errorClass: "has-error"
});
});
</script>
누구든지 스크립트의 기능을 유지할 수 있지만 POST 매개 변수로 클릭 한 단추를 포함하는 방법을 알고 있습니까?
그 양식 제출이 programtic 대신 (즉, 동작이 'preventDefaul()을'호출 방지) 버튼을 클릭함으로써 완료되지 않기 때문이다 클릭 한 버튼에 대해 알지 못하는 양식 제출 –