2016-06-11 1 views
2

일부 입력이 숨겨진 상태가 아닌 경우 "필수"로만 설정하도록 조언하고 있습니다.div가 숨겨져 있지 않은 경우에만 텍스트 입력이 필요합니까?

function ShowHide(){ 
if(document.getElementById('addressY').checked){ 
    document.getElementById("addressT").style.display = "block"; 
} else { 
    document.getElementById("addressT").style.display = "none"; 
    } 
} 

그리고 숨겨진 DIV 입력 양식의 예 : 당신은 모든 형태의 예에서 볼 수

<label class="col-md-4 control-label" for="radios"><b>Did you find an address where the company accepts payments?</b></label> 
<div class="col-md-4"> 
<div class="radio"><label for="radios-1"><input id="addressY" name="spelling" onchange="ShowHide()" required="" type="radio" value="yes" /> Yes </label></div> 

<div class="radio"><input id="addressN" name="spelling" onchange="ShowHide()" required="" type="radio" value="no" /> No</div> 
</div> 
</div> 

<div id="addressT" style="display: none;">&nbsp; 
<div class="form-group"><b><label class="col-md-4 control-label" for="Full Address">Please fill in the full address that you found.</label> </b> 

<div class="col-md-4"><label for="radios-0">Make Check Payable To (Optional): <input class="form-control input-md" id="address1" name="address1" placeholder="" style="width: 100%;" type="text" /></label>  
</div> 

여기

내가 숨겨진 사업부를 표시하는 데 사용하는 자바 스크립트입니다 액션 here.

이 작업을 수행하는 더 좋은 방법을 생각할 수 있다면이 말을 듣고 싶습니다. 나는 자바 스크립트와 jquery의 상대적인 초보자이다. 당신이 요소를 숨기고 문제가 너무 를 해결 한 후 라디오 버튼을 사용하지 않으면 다음

+0

숨어 모두가 아마 –

+0

을 할 것 해제하는 것은 내 도움이되는 대답 ??? –

답변

1

,

function ShowHide(){ 
if(document.getElementById('addressY').checked){ 
    document.getElementById("addressT").style.display = "block"; 
    for (var i=0, iLen=radios.length; i<iLen; i++) { 
      radios[i].disabled = false; 
     } 
} else { 
    document.getElementById("addressT").style.display = "none"; 
     var radios = document.querySelectorAll("[name='addresstype']") 

     for (var i=0, iLen=radios.length; i<iLen; i++) { 
      radios[i].disabled = true; 
     } 
    } 
} 
+0

안녕하세요. 방금이 솔루션을 사용해 보았습니다. 불행히도 여전히 문제가 발생하고 있습니다. div가 숨겨져 있어도 양식에서 제출을 허용하지 않습니다. 당신이 생각할 수있는 다른 가능한 해결책은 무엇입니까? – Rob

+0

@Rob : 귀하의 링크에서이 솔루션을 시도했는데 성공했습니다 ... –

+0

@Rob : jquery가 귀하의 페이지에 추가 된 것을 볼 수 없습니다 –

0

이 같은 시도 :

function ShowHide(){ 
if(document.getElementById('addressY').checked){ 

document.getElementById("addressT").style.display = "block"; 
document.getElementById("divWithRadioButtons").innerHTML = "Write your html code for those radio buttons and make them required" 
} else { 
document.getElementById("addressT").style.display = "none"; 
document.getElementById("divWithRadioButtons").innerhtml=""; 
} 
} 
+0

'innerHTML' (대소 문자 구별)은 함수가 아니며 속성입니다. – freefaller

+0

@freefaller 지적 해 주셔서 감사합니다 ... document.getElementById ("divWithRadioButtons")로 편집합니다 innerHTML = 'Your code' –

관련 문제