COMING SOON 🚀

onclick 과 onkeyup을 하나의 변수에 동시에 사용하면 안되는 건가요?

라디오버튼으로 숫자를 선택하면 아래에 그래프로 표시되도록 구현했는데요,
이 부분은 잘 작동합니다.
그런데 여기에서 텍스트박스에 직접 입력하기를 함께 사용하려고 하는데 직접입력 부분이 전혀 작동을 하지 않습니다.

onclick 과 onkeyup을 하나의 변수에 동시에 사용하면 안되는 건가요?
무엇이 잘못된 건지 모르겠습니다.

-------------------------------------------------------------------------------------------------------
<!--라디오선택 부분-->
<input type="radio" name="wr_1" value="100" id="wr_1" onclick="changebar(this.value);">100<br>
<input type="radio" name="wr_1" value="200" id="wr_1" onclick="changebar(this.value);">200<br>
<input type="radio" name="wr_1" value="300" id="wr_1" onclick="changebar(this.value);">300<br>
<!--직접입력 부분-->
직접입력 : <input type="text" size=10 id="wr_1" name="wr_1" itemname="숫자" numeric value="" onkeyup="changebar(this.value);" onfocus="this.value='';"> 


<script type="text/javascript">
function changebar(score) {
  limitmon = document.fviewcomment.wr_1.value;
  if (limitmon < 0 || limitmon > 300  || limitmon.length < 1) { 
    alert("점수를 0~300점 사이로 점수를 주셔야 합니다.");
    document.fviewcomment.wr_1.value= document.fviewcomment.wr_1.value.replace(/\D/g,'') ;
document.fviewcomment.wr_1.value = '';
document.getElementById("bar").width = '';
    document.fviewcomment.wr_1.focus();
    return false; 
    } 
  document.getElementById("bar").width = parseInt(score)*1;
  } 
</script>

<!--그래프로 나타나는 부분-->
<img src="../img/bar.jpg" id="bar" width="0" height="16"> 
-------------------------------------------------------------------------------------------------------

도움주시면 감사하겠습니다.
|

댓글 9개

onkeypress 혹은 onkeydown이벤트를 이용해보세요.
네 답변 감사합니다.
하지만 말씀하신대로 해보아도 안되는데요, 혹시 다른 문제가 있는 것 아닐지요?
javascript:changebar(this.value); 이렇게 해보심이... 이래도 안되면 지지 ㅠㅠ
아니면 jquery로 $(object).keypress이벤트를 걸어도 됩니다.
<!--라디오선택 부분-->
<input type="radio" name="wr_1" value="100" id="wr_1" onclick="changebar(this.value);">100<br>
<input type="radio" name="wr_1" value="200" id="wr_2" onclick="changebar(this.value);">200<br>
<input type="radio" name="wr_1" value="300" id="wr_3" onclick="changebar(this.value);">300<br>
<!--직접입력 부분-->
직접입력 : <input type="text" size=10 id="wr_4" name="wr_1" itemname="숫자" numeric value="" onkeyup="changebar(this.value);" onfocus="this.value='';">




<script type="text/javascript">
function changebar(score) {
limitmon = document.getElementById("wr_4").value;
if (limitmon < 0 || limitmon > 300 ) {
alert("점수를 0~300점 사이로 점수를 주셔야 합니다.");
limitmon.focus();
return false;
}
document.getElementById("bar").width = parseInt(score)*1;
}
</script>


<!--그래프로 나타나는 부분-->
<img src="../img/bar.jpg" id="bar" width="0" height="16">


name은 사람 이름하고 같습니다 즉 중복이 가능하나
id는 주민번호와 같아서 절대 중복이 있어서는 안됩니다
네임값으로 접근하실려면 배열로 접근해야 합니다
오 예리하셔... ID가 같은걸 아무도 모르고 있었는데!!
한수 배웁니다 ^^
답변 정말 감사드립니다~~~
자바스크립트 짜다가 해결되지 않거나 막히면 f12눌러 보세요
어디에서 오류가 있는지 기본적으로 볼수 있는 개발자 도구가 익스7이상부터는 제공합니다
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

+
제목 글쓴이 날짜 조회
13년 전 조회 1,700
13년 전 조회 1,777
13년 전 조회 2,289
13년 전 조회 1,894
13년 전 조회 2,118
13년 전 조회 2,410
13년 전 조회 1,946
13년 전 조회 2,882
13년 전 조회 1,867
13년 전 조회 1,869
13년 전 조회 2,363
13년 전 조회 2,501
13년 전 조회 3,170
13년 전 조회 1,831
13년 전 조회 1,943
13년 전 조회 1,849
13년 전 조회 2,510
13년 전 조회 3,105
13년 전 조회 2,231
13년 전 조회 2,526
13년 전 조회 1,936
13년 전 조회 1,657
13년 전 조회 1,757
13년 전 조회 2,253
13년 전 조회 2,978
13년 전 조회 2,759
13년 전 조회 2,350
13년 전 조회 2,394
13년 전 조회 1,666
13년 전 조회 1,912
13년 전 조회 3,185
13년 전 조회 1,785
13년 전 조회 1,793
13년 전 조회 5,723
13년 전 조회 2,362
13년 전 조회 4,374
13년 전 조회 1,855
13년 전 조회 1,922
13년 전 조회 1,937
13년 전 조회 1,825
13년 전 조회 2,425
13년 전 조회 1,804
13년 전 조회 1,836
13년 전 조회 3,238
13년 전 조회 1,643
13년 전 조회 3,396
13년 전 조회 2,569
13년 전 조회 2,073
13년 전 조회 1,873
13년 전 조회 2,917
13년 전 조회 1,614
13년 전 조회 2,178
13년 전 조회 2,363
13년 전 조회 2,230
13년 전 조회 1,692
13년 전 조회 1,892
13년 전 조회 2,160
13년 전 조회 4,700
13년 전 조회 4,309
13년 전 조회 4,868
13년 전 조회 4,169
13년 전 조회 1,694
13년 전 조회 1,722
13년 전 조회 1,812
13년 전 조회 1만
13년 전 조회 3,275
13년 전 조회 3,757
13년 전 조회 3,695
13년 전 조회 4,239
13년 전 조회 1,819
13년 전 조회 1,884
13년 전 조회 5,777
13년 전 조회 1,809
13년 전 조회 2,538
13년 전 조회 2,293
13년 전 조회 2,404
13년 전 조회 2,231
13년 전 조회 1,718
13년 전 조회 2,425
13년 전 조회 1,886
13년 전 조회 2,573
13년 전 조회 2,198
13년 전 조회 1,878
13년 전 조회 3,185
13년 전 조회 2,188
13년 전 조회 1,803
13년 전 조회 3,379
13년 전 조회 2,321
13년 전 조회 2,316
13년 전 조회 2,448
13년 전 조회 2,183
13년 전 조회 1,684
13년 전 조회 1,707
13년 전 조회 2,685
13년 전 조회 1,928
13년 전 조회 2,911
13년 전 조회 2,415
13년 전 조회 1,726
13년 전 조회 5,165
13년 전 조회 1,881