2012-03-16 4 views
0

누군가 내가 잘못하고있는 것을 지적 할 수 있다면 영원히 감사 할 것입니다! 나는 괄호의 올바른 조합을 얻을 수없는 것 같습니다. 어떻게 하나의 문장에서 여러 조건을 결합 할 수 있습니까? 분명히 나는 ​​아래 코드를 수정할 사람이있을 것이라고 기대하지 않고 단지 달성하려는 것을 보여주고 싶다. 누군가가 나에게 논리를 설명 할 수있는 경우자바 스크립트 조건

은 당신이 그것의 괄호

if (document.forms[0].IPR.value == "" && document.forms[0].FNM1.value == "" && ect...) 

을 닫지 마십시오 큰

감사

function ChangeButton() 
{ 
if 
((document.forms[0].IPR.value == "") && (document.forms[0].FNM1.value == "") && (document.forms[0].FNM1.value == "") && (document.forms[0].SURN.value == "") && (document.forms[0].GEND.value == "") && (document.forms[0].DOB.value == "") && (document.forms[0].CRIM.value == "") && (document.forms[0].ETHC.value == "") && (document.forms[0].DSBC.value == "") && (document.forms[0].MARK1.value == "") && (document.forms[0].NATC.value == "") && (document.forms[0].COBC.value == "") && (document.forms[0].COD.value == "") && (document.forms[0].FIVE.value == "") && (document.forms[0].PERM.value == "") && (document.forms[0].VISF.value == "") && (document.forms[0].USD.value == "") && (document.forms[0].HAD1.value == "") && (document.forms[0].HAD3.value == "") && (document.forms[0].HTEL.value == "") && (document.forms[0].HAEM.value == "") && (document.forms[0].FEES.value == "") && (document.forms[0].REF1TIT.value == "") && (document.forms[0].REF1ORG.value == "")  && (document.forms[0].REF1POS.value == "") && (document.forms[0].REF1AL1.value == "") && (document.forms[0].REF1AL3.value == "") && (document.forms[0].REF1AL5.value == "") && (document.forms[0].REF1EMA.value == "") && (document.forms[0].DISC.value == "")) 
&& 
((document.forms[0].PERM.value == "") && (document.forms[0].FIVE.value == "N")) 
&& 
((document.forms[0].AGNT.value == "") && (document.forms[0].USD.value == "Y")) 
&& 
((document.forms[0].CSTRT.value == "") && (document.forms[0].USD.value == "N") && (document.forms[0].CENDD.value == "") && (document.forms[0].CAD1.value == "") && (document.forms[0].CAD3.value == "") && (document.forms[0].CAD4.value == "") && (document.forms[0].CAPC.value == "") && (document.forms[0].CTEL.value == "")) 
&& 
((document.forms[0].AWDB.value == "") && (document.forms[0].FEES.value == "") && (document.forms[0].FEES.value == "Private Funds Self or Family") && (document.forms[0].AWDS.value == "")) 
&& 
((document.forms[0].RESEARCH.value == "Y") && (document.forms[0].RESSRT.value == "") && (document.forms[0].RESMOA.value == "") && (document.forms[0].RESAR.value == "") && (document.forms[0].RESDIS.value == "")) 
{ 
document.getElementById('submitbutton').className = 'enabled'; 
} 
else { 
document.getElementById('submitbutton').className = 'disabled'; 
} 
} 
+0

아마도 일부 JQuery와 순서에있을 수 있습니다? –

+0

우리가해야할 일이 무엇인지 모를 때 왜 어떤 코드가 "틀린"이유인지를 설명하는 것은 실제로는 다릅니다. – Quentin

+0

무엇이 질문입니까? 오류가 있습니까? 네가하고있는 일은 나에게 좋은 것처럼 보인다. – Th0rndike

답변

0

나는이 사실이 결코

...&&... document.forms[0].FIVE.value == "" 
...&&... document.forms[0].FIVE.value == "N" 

볼 이클립스

편집

나는 접근 방식을 바꾸어야한다고 생각하는데, 다음과 같이 시도해보십시오 :

,210
function ChangeButton() 
{ 
    var frm = document.forms[0]; 
    var neverEmpty = ['field1','field2','field3']; 
    var mustBe  = {field3:'Y', field4:'N'}; 

    var status = 'ok'; 

    for(var i = 0; i<neverEmpty.length; i++) { 
     if(frm[neverEmpty[i]] == '') { 
     status = 'ko'; 
     break; 
    } 
} 

for(myField in mustBe) { 
    if(frm[myfield] != mustBe[myField]) { 
     status = 'ko'; 
     break; 
    } 
} 
document.getElementById('submitbutton').className = status=='ok'? 'enabled' : 'disabled'; 

}

+0

좋은 장소, 그래서 사용해야합니다 | | 대신에? – Marcus

+0

그것은 ... 당신은 무엇을 할 것입니까? –

0

것 간단

+0

Chrome의 콘솔에서 문제가 있다고 말하면서 계속 시도 했습니까? 제안 해 주셔서 감사 드리며 계속 노력하겠습니다. – Marcus

0

전체 괄호 주위에 괄호 세트가 하나 더 필요합니다. if (a == b) {..}

0

지금까지 보았 듯이 괄호 (여기에는 if 구문이 필요한 경우 제외)는 필요하지 않습니다.

if(document.forms[0].IPR.value == "" && document.forms[0].FNM1.value == "" && 
    document.forms[0].PERM.value == "" && document.forms[0].FIVE.value == "N" && 
    ... 
    ) { 
    document.getElementById('submitbutton').className = 'enabled'; 
} else { 
    document.getElementById('submitbutton').className = 'disabled'; 
} 
0

비어 있지 않아야하는 입력 요소에 "클래스"속성을 지정하십시오. 그 미친 못생긴 코드를 작성하는 대신 그 모든 요소를 ​​사용하십시오.

+0

고마워요. 아마 말할 수 있듯이, 저는 JavaScript가 처음이에요. 당신의 제안 된 방법을 연구 할 것입니다 – Marcus

+0

불행히도 그럴 필요가 없습니다. 클래스 속성은 Uniface – Marcus

0

당신은 하나 더 괄호 이전과 ( ... ) {...} 여기

0

가 수정 된 코드 인 경우 첫 번째 중괄호 모든 것을하기 전에해야합니다.

function ChangeButton() 
{ 
    if 
    ((document.forms[0].IPR.value == "") && (document.forms[0].FNM1.value == "") && (document.forms[0].FNM1.value == "") && (document.forms[0].SURN.value == "") && (document.forms[0].GEND.value == "") && (document.forms[0].DOB.value == "") && (document.forms[0].CRIM.value == "") && (document.forms[0].ETHC.value == "") && (document.forms[0].DSBC.value == "") && (document.forms[0].MARK1.value == "") && (document.forms[0].NATC.value == "") && (document.forms[0].COBC.value == "") && (document.forms[0].COD.value == "") && (document.forms[0].FIVE.value == "") && (document.forms[0].PERM.value == "") && (document.forms[0].VISF.value == "") && (document.forms[0].USD.value == "") && (document.forms[0].HAD1.value == "") && (document.forms[0].HAD3.value == "") && (document.forms[0].HTEL.value == "") && (document.forms[0].HAEM.value == "") && (document.forms[0].FEES.value == "") && (document.forms[0].REF1TIT.value == "") && (document.forms[0].REF1ORG.value == "")  && (document.forms[0].REF1POS.value == "") && (document.forms[0].REF1AL1.value == "") && (document.forms[0].REF1AL3.value == "") && (document.forms[0].REF1AL5.value == "") && (document.forms[0].REF1EMA.value == "") && (document.forms[0].DISC.value == "") 
     && 
     ((document.forms[0].PERM.value == "") && (document.forms[0].FIVE.value == "N")) 
     && 
     ((document.forms[0].AGNT.value == "") && (document.forms[0].USD.value == "Y")) 
     && 
     ((document.forms[0].CSTRT.value == "") && (document.forms[0].USD.value == "N") && (document.forms[0].CENDD.value == "") && (document.forms[0].CAD1.value == "") && (document.forms[0].CAD3.value == "") && (document.forms[0].CAD4.value == "") && (document.forms[0].CAPC.value == "") && (document.forms[0].CTEL.value == "")) 
     && 
     ((document.forms[0].AWDB.value == "") && (document.forms[0].FEES.value == "") && (document.forms[0].FEES.value == "Private Funds Self or Family") && (document.forms[0].AWDS.value == "")) 
     && 
     ((document.forms[0].RESEARCH.value == "Y") && (document.forms[0].RESSRT.value == "") && (document.forms[0].RESMOA.value == "") && (document.forms[0].RESAR.value == "") && (document.forms[0].RESDIS.value == ""))) 
     { 
     document.getElementById('submitbutton').className = 'enabled'; 
     } 
    else { 
     document.getElementById('submitbutton').className = 'disabled'; 
    } 
} 

사용 및 IDE, 그것은 UR의 인생을 간단하게합니다 .. 건배 IDE :

+0

을 통해 동적으로 추가됩니다. 환호 :) – Marcus