2015-02-06 1 views
0

은 3 쌍 사용자가 체크 상자를 클릭하고 최소 또는 최대 수준을 설정하지 않은 경우 아래 jquery 코드입니다. 텍스트 입력란에 양식을 입력하지 않아야합니다. 예를 들어 MinLevelA 및 MaxLevelA 값이 선택되었거나 하나의 쌍 값이 선택되면 양식을 제출해야 함을 의미합니다. 유효성 검사 만. 값이 0이면 image attached for my view3 쌍 중 한 쌍이 선택되면 양식을 제출해서는 안됩니다.

$('#ParLevelSettings').on("click", ".Savebtn", function (event) { //on click 
    var isValid = true; 

    $('#ParLevelSettings input.isincludechk:checked, #ParLevelSettings input.ischanged[value="true"]').closest('div.row-fluid').find('.minlvl').each(function() { 
     var min = $(this).get(0); 
     var max = $(this).closest('div').next('div').find('.maxlvl').get(0) 
     var dataVal = $(this).data("ichange"); 
     var minval = parseInt(min.value); 
     var maxval = parseInt(max.value); 

     if(minval != 0 && maxval != 0) 
     { 
      var isSet = $("#isSet_" + dataVal); 
      isSet.val(true); 
      return; 
     } 
      if (isNaN(minval) || minval > maxval) { 
       $(min).css({ 
        "border": "1px solid red", 
        "background": "#FFCECE" 
       }); 
       $(min).attr('title', 'Min level should not be empty or Min level should be less than the Max level or must give some value to min level'); 
       isValid = false; 
      } 
     else { 
      $(min).css({ 
       "border": "", 
       "background": "" 
      }); 
     } 
     if (isNaN(maxval) || maxval < minval) { 
      $(max).css({ 
       "border": "1px solid red", 
       "background": "#FFCECE" 
      }); 

      $(max).attr('title', 'Max level should not be empty or Max level should be greater than the Min level or must give some value to min level'); 
      isValid = false; 
     } 
     else { 
      $(max).css({ 
       "border": "", 
       "background": "" 
      }); 
     } 
    }); 

    if (isValid == false) event.preventDefault(); 
}); 
+0

그래서 그것은 제출하지 않겠습니까? – Garrett

+0

모든 값이 0이면 사용자가 MINLevelA 또는 MaxLevelB 값을 제공하고 양식을 제출해야하는 경우 제출해서는 안됩니다. –

답변

1
$("#formID").on("submit", function(){ 
//use the condition in your example 
    if(condition==true){ 
      return true; 
    } 
    else{ 
      //display some reason why the form was not submitted. 
      return false; 
    } 
}); 
+0

양식에 값을 제출해야합니다. 확인란이 선택되어 있고 한 행에 두 개의 텍스트 상자에 값을 지정하면 ... –

+0

ajax를 사용하여 각 행의 변경 사항을 POST하려고합니까? – Ryan

+0

nops 서버 호출을 요청하고 있습니다. –

관련 문제