2016-08-03 3 views
0

2 개의 체크 박스를 추가 한 후 완벽하게 작동하지 않는 어리석은 작은 스크립트. 목표는 동적 매개 변수가있는 URL을 여는 것입니다. 가능한 오류를 찾기 위해 인터넷 검색을했지만 찾지 못했습니다. DOM 속성은 요청 된대로 스크립트 앞에 선언됩니다.자바 스크립트 체크 박스 document.getElementById가 null을 반환합니다.

어떤 아이디어가 있습니까? 당신이

<body> 
<table border="0"> 
    <tr> 
     <td>Serial Number</td> 
     <td><input type="text" id="deviceUdid" value="251528003720" maxlength="12" size="10"></td> 
    </tr> 
    <tr> 
     <td>HouseHold</td> 
     <td><input type="checkbox" id="Household" value="1"></tr> 
    <tr> 
     <td>Community</td> 
     <td><input type="checkbox" id="Communities"></tr> 
    <tr> 
     <td><input type="button" id="btn" value="Submit" onClick="form_submit()"></tr> 
</table> 

<script type="text/javascript"> 
    function form_submit() { 
     var a = 'https://test?'; 
     a += 'ACTION=authenticateUniqueDevice'; 
     a += '&deviceUdid=' + document.getElementById('deviceUdid').value; 
     a += '&CONTENT_READ_KEY=dddddddddd'; 
     if (document.getElementById('HouseHold').checked) a += '&includeHousehold=true'; 
     if (document.getElementById('Communities').checked) a += '&includeHouseholdCommunities=true'; 
     window.open(a, 'MyWindow', 'width=600,height=700'); 

    } 
</script> 

+0

완벽하게 작동하지 않습니다 ... 그래서 작동합니까 어떻게, 무엇을 어떻게해야합니까? 너는 무엇을 기대 하느냐? –

+2

HouseHold! == 가정용 –

+0

개발자 도구 콘솔 로그는이 오타를 식별합니다 –

답변

0

변경 (아래로)이 줄을 감사하는 경우가 HTML 및 스크립트 블록 사이에 Household 텍스트로 차이가 보인다.

if (document.getElementById('Household').checked) a += '&includeHousehold=true'; 

는 스크립트 블록 개정

<script type="text/javascript"> 
    function form_submit() { 
     var a = 'https://test?'; 
     a += 'ACTION=authenticateUniqueDevice'; 
     a += '&deviceUdid=' + document.getElementById('deviceUdid').value; 
     a += '&CONTENT_READ_KEY=dddddddddd'; 
     if (document.getElementById('Household').checked) a += '&includeHousehold=true'; 
     if (document.getElementById('Communities').checked) a += '&includeHouseholdCommunities=true'; 
     window.open(a, 'MyWindow', 'width=600,height=700'); 

    } 
</script> 
+0

정말 혼란 스럽습니다.이 오타가 잘못되었습니다. 고맙습니다 ! – ThomasP

관련 문제