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,698
13년 전 조회 1,773
13년 전 조회 2,285
13년 전 조회 1,890
13년 전 조회 2,114
13년 전 조회 2,407
13년 전 조회 1,944
13년 전 조회 2,879
13년 전 조회 1,861
13년 전 조회 1,865
13년 전 조회 2,359
13년 전 조회 2,494
13년 전 조회 3,166
13년 전 조회 1,828
13년 전 조회 1,940
13년 전 조회 1,845
13년 전 조회 2,508
13년 전 조회 3,101
13년 전 조회 2,229
13년 전 조회 2,525
13년 전 조회 1,932
13년 전 조회 1,651
13년 전 조회 1,754
13년 전 조회 2,247
13년 전 조회 2,972
13년 전 조회 2,753
13년 전 조회 2,346
13년 전 조회 2,385
13년 전 조회 1,662
13년 전 조회 1,910
13년 전 조회 3,183
13년 전 조회 1,780
13년 전 조회 1,789
13년 전 조회 5,715
13년 전 조회 2,357
13년 전 조회 4,370
13년 전 조회 1,854
13년 전 조회 1,917
13년 전 조회 1,934
13년 전 조회 1,824
13년 전 조회 2,421
13년 전 조회 1,800
13년 전 조회 1,831
13년 전 조회 3,236
13년 전 조회 1,642
13년 전 조회 3,395
13년 전 조회 2,566
13년 전 조회 2,070
13년 전 조회 1,866
13년 전 조회 2,912
13년 전 조회 1,611
13년 전 조회 2,174
13년 전 조회 2,359
13년 전 조회 2,225
13년 전 조회 1,688
13년 전 조회 1,887
13년 전 조회 2,156
13년 전 조회 4,697
13년 전 조회 4,306
13년 전 조회 4,865
13년 전 조회 4,164
13년 전 조회 1,689
13년 전 조회 1,719
13년 전 조회 1,804
13년 전 조회 1만
13년 전 조회 3,273
13년 전 조회 3,753
13년 전 조회 3,687
13년 전 조회 4,230
13년 전 조회 1,815
13년 전 조회 1,875
13년 전 조회 5,774
13년 전 조회 1,807
13년 전 조회 2,537
13년 전 조회 2,287
13년 전 조회 2,397
13년 전 조회 2,223
13년 전 조회 1,714
13년 전 조회 2,420
13년 전 조회 1,880
13년 전 조회 2,567
13년 전 조회 2,193
13년 전 조회 1,875
13년 전 조회 3,182
13년 전 조회 2,184
13년 전 조회 1,802
13년 전 조회 3,374
13년 전 조회 2,319
13년 전 조회 2,311
13년 전 조회 2,445
13년 전 조회 2,179
13년 전 조회 1,678
13년 전 조회 1,704
13년 전 조회 2,681
13년 전 조회 1,923
13년 전 조회 2,903
13년 전 조회 2,410
13년 전 조회 1,723
13년 전 조회 5,159
13년 전 조회 1,879