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,691
13년 전 조회 1,766
13년 전 조회 2,281
13년 전 조회 1,886
13년 전 조회 2,106
13년 전 조회 2,403
13년 전 조회 1,936
13년 전 조회 2,874
13년 전 조회 1,853
13년 전 조회 1,859
13년 전 조회 2,358
13년 전 조회 2,491
13년 전 조회 3,159
13년 전 조회 1,825
13년 전 조회 1,937
13년 전 조회 1,842
13년 전 조회 2,502
13년 전 조회 3,096
13년 전 조회 2,225
13년 전 조회 2,520
13년 전 조회 1,928
13년 전 조회 1,646
13년 전 조회 1,743
13년 전 조회 2,242
13년 전 조회 2,965
13년 전 조회 2,749
13년 전 조회 2,342
13년 전 조회 2,381
13년 전 조회 1,660
13년 전 조회 1,905
13년 전 조회 3,180
13년 전 조회 1,779
13년 전 조회 1,781
13년 전 조회 5,710
13년 전 조회 2,347
13년 전 조회 4,368
13년 전 조회 1,847
13년 전 조회 1,914
13년 전 조회 1,930
13년 전 조회 1,816
13년 전 조회 2,415
13년 전 조회 1,798
13년 전 조회 1,827
13년 전 조회 3,232
13년 전 조회 1,641
13년 전 조회 3,387
13년 전 조회 2,560
13년 전 조회 2,064
13년 전 조회 1,861
13년 전 조회 2,910
13년 전 조회 1,607
13년 전 조회 2,171
13년 전 조회 2,355
13년 전 조회 2,218
13년 전 조회 1,680
13년 전 조회 1,883
13년 전 조회 2,152
13년 전 조회 4,688
13년 전 조회 4,304
13년 전 조회 4,860
13년 전 조회 4,159
13년 전 조회 1,686
13년 전 조회 1,717
13년 전 조회 1,802
13년 전 조회 1만
13년 전 조회 3,269
13년 전 조회 3,749
13년 전 조회 3,683
13년 전 조회 4,224
13년 전 조회 1,809
13년 전 조회 1,869
13년 전 조회 5,772
13년 전 조회 1,799
13년 전 조회 2,530
13년 전 조회 2,280
13년 전 조회 2,393
13년 전 조회 2,220
13년 전 조회 1,709
13년 전 조회 2,414
13년 전 조회 1,877
13년 전 조회 2,564
13년 전 조회 2,187
13년 전 조회 1,868
13년 전 조회 3,178
13년 전 조회 2,180
13년 전 조회 1,798
13년 전 조회 3,371
13년 전 조회 2,313
13년 전 조회 2,303
13년 전 조회 2,441
13년 전 조회 2,177
13년 전 조회 1,676
13년 전 조회 1,698
13년 전 조회 2,676
13년 전 조회 1,920
13년 전 조회 2,901
13년 전 조회 2,406
13년 전 조회 1,717
13년 전 조회 5,152
13년 전 조회 1,873