我是cakePHP的新手,我在cakePHP中提交了按钮
$ajax->submit(
'Submit',
array(
"update" => "gridbox_script",
"url" => '/flots/comparaison_gridbox_update',
"div"=>"button_submit",
"loading" => "setIboxOpacity = setOpacity;showBG();showIndicator();" ,
"complete" => "hideBG();hideIndicator()"
)
);
我想添加一个javascript验证,如果验证返回true,那么它应该继续提交,否则提交应该终止。
整个提交是通过ajax调用的,我被建议使用$ajax
来实现。
我的javascript函数:
var firstCompare = new Array();
fucntion myValidation(){
var otherCompare = new Array();
if(document.getElementById("file1").checked)
otherCompare.push('file1');
result = (otherCompare.length === _.intersection(otherCompare, firstCompare).length);
firstCompare = otherCompare;
return result;
}
请帮帮我。
答案 0 :(得分:0)
使用for id并检查提交或点击按钮事件。
$(document).ready(function() {
$('#formId').on('submit', function() {
var val = your_function() //call the function and store the return value
if (val) {
//do the submission
} else {
//code in case of false
}
});
});