자바스크립트 오류 문의 (랜덤추첨기) 채택완료
ideaman
2년 전
조회 2,300
아래의 소스에서 "응모자 목록" 을 10명으로 만들었는데 2명을 뽑으려고 하니 아래와 같은 오류가 뜹니다\
어디를 수정해야 할까요 ㅠㅠ

</p>
<p>
<!doctype html></p>
<p><html lang="en"></p>
<p><head></p>
<p> <meta name="viewport" content="width=device-width, initial-scale=1.0" /></p>
<p> <META NAME="Keywords" CONTENT="당첨자 추첨하기, 추첨하기, 컴퓨터 추첨"></p>
<p> <META NAME="Description" CONTENT="당첨자 추첨하기, 추첨하기, 컴퓨터 추첨"></p>
<p> <title>당첨자 추첨하기</title></p>
<p> <link rel="icon" href="//apps.ojj.kr/favicon.ico" type="image/x-icon"></p>
<p> <!-- Bootstrap 5 CSS --></p>
<p> <link href="<a href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css"" target="_blank" rel="noopener noreferrer">https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css"</a> rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous"></p>
<p> <script src="<a href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.bundle.min.js"" target="_blank" rel="noopener noreferrer">https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.bundle.min.js"</a> integrity="sha384-gtEjrD/SeCtmISkJkNUaaKMoLD0//ElJ19smozuHV6z3Iehds+3Ulb9Bn9Plx0x4" crossorigin="anonymous"></script></p>
<p> <style></p>
<p> td {font-size : 10pt; line-height:140%; font-family:dotum;}</p>
<p> .header_title {</p>
<p> font-family: verdana;</p>
<p> font-weight: bold;</p>
<p> font-size: xx-large;</p>
<p> text-decoration: none;</p>
<p> color:NAVY;</p>
<p> }</p>
<p> .table_frame {</p>
<p> width: 100%;</p>
<p> max-width: 600px;</p>
<p> /*text-align: center;*/</p>
<p> margin: auto;</p>
<p> border: none;</p>
<p> align-self: center;</p>
<p> }</p>
<p> </style></p>
<p></head></p>
<p><body style="margin-top: 70px">
<script type="text/javascript">
function count_apply_list()
{
var form = document.winnerForm;
var lines;</p>
<p> form.apply_list.value = form.apply_list.value.trim();
lines = form.apply_list.value.split(/\r\n|\r|\n/);</p>
<p> form.apply_count.value = lines.length;
}
function get_winner()
{
var form = document.winnerForm;
var lines = [];
//var apply_list = new String(form.apply_list.value);
var winner_list = []
var winner_count = 0;</p>
<p> apply_list = form.apply_list.value;
if ( apply_list.length == 0 )
{
alert('응모자 목록을 2명(줄) 이상 입력하세요. ');
form.apply_list.focus();
return;
}
lines = apply_list.split(/\r\n|\r|\n/);
form.apply_count.value = lines.length;
//alert(lines.length);
if ( lines.length < 2 )
{
alert('응모자 목록을 2명(줄) 이상 입력하세요. ');
form.apply_list.focus();
return;
}</p>
<p> if ( form.winner_count.value == '' )
{
alert('당첨자 수를 입력하세요. ');
form.winner_count.focus();
return;
}
else if ( isNaN(form.winner_count.value) )
{
alert('당첨자 수를 숫자로 입력하세요. ');
form.winner_count.value='';
form.winner_count.focus();
return;
}
else if ( form.apply_count.value <= form.winner_count.value )
{
alert('당첨자 수는 응모자 수(' + form.apply_count.value + ') 보다 작아야 합니다. ');
form.winner_count.value='';
form.winner_count.focus();
return;
}
winner_count = form.winner_count.value;</p>
<p> i=0;
while ( winner_list.length < winner_count )
{
rand_num = Math.floor(Math.random()*lines.length);
check_dup = 0;
for (j=0; j < winner_list.length ; j++ )
{
if ( winner_list[j] == rand_num)
{
check_dup = 1;
break;
}
}
// if not exist in winner_list
if ( check_dup == 0 )
{
winner_list[i] = rand_num;
i++;
}
}
winner_list.sort();
form.winner_list.value = '';
for (idx=0; idx < winner_list.length ; idx++)
{
form.winner_list.value += lines[winner_list[idx]] + '\n';
}
}
</script></p>
<p><div style="margin:auto; text-align: center; max-width: 480px">
<script async src="<a href="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5949021124468292"" target="_blank" rel="noopener noreferrer">https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5949021124468292"</a>
crossorigin="anonymous"></script>
<!-- 수평형_468x80 -->
<ins class="adsbygoogle"
style="display:inline-block;width:100%; max-width:468px;height:80px"
data-ad-client="ca-pub-5949021124468292"
data-ad-slot="9064649802"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>
</p>
<p><form name="winnerForm" method="POST">
<table border=1 cellspacing=1 cellpadding=2 align="center" style="width:100%; max-width: 600px">
<colgroup>
<col width=100>
<col width=*>
</colgroup>
<tr><td align="center"><b>응모자 목록</b>
<input type=text name="apply_count" value=0 size=2 readonly style="text-align:center;"></td>
<td><textarea name="apply_list" style="width:100%; height:200px" onChange="count_apply_list()"></textarea>
<font color=RED>명단은 줄바꿈으로 구분됩니다.</font>
</td>
</tr>
<tr><td align="center"><b>당첨자 수</b></td>
<td><input type="text" name="winner_count" value="1" size=3 maxlength=3> 예) 10 (응모자 수 보다 작게)</td>
</tr>
<tr><td align='center'><b>추첨 결과</b></td>
<td>
<div style="margin:auto; text-align: center; max-width: 480px">
<ins class="kakao_ad_area" style="display:none;"
data-ad-unit = "DAN-WswNxNi4Q0n5chBG"
data-ad-width = "320"
data-ad-height = "100"></ins>
<script type="text/javascript" src="//t1.daumcdn.net/kas/static/ba.min.js" async></script>
</div>
<textarea name="winner_list" style="width:100%;height:200px"></textarea>
</td>
</tr>
</table>
<div style="margin:auto; text-align: center; max-width: 480px">
<input type="button" value=" 추첨! " onClick="get_winner();">
</div>
</form>
<div style="margin:auto; text-align: center; max-width: 480px">
<script async src="<a href="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5949021124468292"" target="_blank" rel="noopener noreferrer">https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5949021124468292"</a>
crossorigin="anonymous"></script>
<!-- 수평형_468x80 -->
<ins class="adsbygoogle"
style="display:inline-block;width:100%; max-width:468px;height:80px"
data-ad-client="ca-pub-5949021124468292"
data-ad-slot="9064649802"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div></p>
<p>
</p>
<p><script>
document.write('<div style="margin:auto; text-align:center; color:#ffffff">현재 모니터 해상도:\n\n' + screen.width + 'x' + screen.height + '</div>');
</script></p>
<p>
<script async src="<a href="https://www.googletagmanager.com/gtag/js?id=UA-1716705-1"></script> " target="_blank" rel="noopener noreferrer">https://www.googletagmanager.com/gtag/js?id=UA-1716705-1"></script> </a>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-1716705-1');
</script></p>
<p><script type="text/javascript" src="//wcs.naver.net/wcslog.js"></script>
<script type="text/javascript">
if(!wcs_add) var wcs_add = {};
wcs_add["wa"] = "cafbfb9609c988";
wcs_do();
</script></p>
<p>
</body></p>
<p></html></p>
<p>
댓글을 작성하려면 로그인이 필요합니다.
답변 2개
채택된 답변
+20 포인트
2년 전
</p>
<p>// else if ( form.apply_count.value <= form.winner_count.value )</p>
<p>else if ( Number(form.apply_count.value) <= Number(form.winner_count.value) )</p>
<p>
로그인 후 평가할 수 있습니다
답변에 대한 댓글 1개
i
ideaman
2년 전
배르만님 감사합니다 이제서야 확인을 했네요 ㅠㅠ
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인