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개
13년 전
onkeypress 혹은 onkeydown이벤트를 이용해보세요.
13년 전
네 답변 감사합니다.
하지만 말씀하신대로 해보아도 안되는데요, 혹시 다른 문제가 있는 것 아닐지요?
하지만 말씀하신대로 해보아도 안되는데요, 혹시 다른 문제가 있는 것 아닐지요?
13년 전
javascript:changebar(this.value); 이렇게 해보심이... 이래도 안되면 지지 ㅠㅠ
13년 전
아니면 jquery로 $(object).keypress이벤트를 걸어도 됩니다.
13년 전
<!--라디오선택 부분-->
<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는 주민번호와 같아서 절대 중복이 있어서는 안됩니다
네임값으로 접근하실려면 배열로 접근해야 합니다
<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는 주민번호와 같아서 절대 중복이 있어서는 안됩니다
네임값으로 접근하실려면 배열로 접근해야 합니다
13년 전
오 예리하셔... ID가 같은걸 아무도 모르고 있었는데!!
13년 전
한수 배웁니다 ^^
13년 전
답변 정말 감사드립니다~~~
13년 전
자바스크립트 짜다가 해결되지 않거나 막히면 f12눌러 보세요
어디에서 오류가 있는지 기본적으로 볼수 있는 개발자 도구가 익스7이상부터는 제공합니다
어디에서 오류가 있는지 기본적으로 볼수 있는 개발자 도구가 익스7이상부터는 제공합니다
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 230 | 20년 전 | 2036 | ||
| 229 | 20년 전 | 3131 | ||
| 228 | 20년 전 | 3322 | ||
| 227 | 20년 전 | 2383 | ||
| 226 | 20년 전 | 5458 | ||
| 225 | 20년 전 | 2506 | ||
| 224 | 20년 전 | 2950 | ||
| 223 | 20년 전 | 4195 | ||
| 222 | 20년 전 | 2594 | ||
| 221 | 20년 전 | 2277 | ||
| 220 | 20년 전 | 3665 | ||
| 219 | 20년 전 | 2062 | ||
| 218 | 20년 전 | 3550 | ||
| 217 | 20년 전 | 2467 | ||
| 216 | 20년 전 | 2894 | ||
| 215 | 20년 전 | 2201 | ||
| 214 | 20년 전 | 3324 | ||
| 213 | 20년 전 | 2909 | ||
| 212 | 20년 전 | 3038 | ||
| 211 | 20년 전 | 2136 | ||
| 210 | 20년 전 | 1863 | ||
| 209 | 20년 전 | 2330 | ||
| 208 | 20년 전 | 1961 | ||
| 207 | 20년 전 | 1661 | ||
| 206 | 20년 전 | 1848 | ||
| 205 | 20년 전 | 3936 | ||
| 204 | 20년 전 | 1666 | ||
| 203 | 20년 전 | 1999 | ||
| 202 | 20년 전 | 2337 | ||
| 201 | 20년 전 | 1813 | ||
| 200 | 20년 전 | 2942 | ||
| 199 | 20년 전 | 1997 | ||
| 198 | 20년 전 | 2077 | ||
| 197 | 20년 전 | 3641 | ||
| 196 | 20년 전 | 2960 | ||
| 195 | 20년 전 | 2083 | ||
| 194 | 20년 전 | 10227 | ||
| 193 | 20년 전 | 2235 | ||
| 192 | 20년 전 | 1578 | ||
| 191 | 20년 전 | 2648 | ||
| 190 | 20년 전 | 2280 | ||
| 189 | 20년 전 | 1669 | ||
| 188 | 20년 전 | 1463 | ||
| 187 | 20년 전 | 1892 | ||
| 186 | 20년 전 | 1691 | ||
| 185 | 20년 전 | 1725 | ||
| 184 | 20년 전 | 2326 | ||
| 183 | 20년 전 | 1537 | ||
| 182 | 20년 전 | 1473 | ||
| 181 | 20년 전 | 1612 | ||
| 180 | 20년 전 | 2707 | ||
| 179 | 20년 전 | 1786 | ||
| 178 | 20년 전 | 1841 | ||
| 177 | 20년 전 | 1967 | ||
| 176 | 20년 전 | 1790 | ||
| 175 | 20년 전 | 1862 | ||
| 174 | 20년 전 | 1684 | ||
| 173 | 20년 전 | 2051 | ||
| 172 | 20년 전 | 1771 | ||
| 171 | 20년 전 | 2549 | ||
| 170 | 20년 전 | 2255 | ||
| 169 | 20년 전 | 2535 | ||
| 168 | 20년 전 | 1464 | ||
| 167 | 20년 전 | 1563 | ||
| 166 | 20년 전 | 2136 | ||
| 165 | 20년 전 | 1600 | ||
| 164 | 20년 전 | 3745 | ||
| 163 | 20년 전 | 2634 | ||
| 162 | 20년 전 | 2062 | ||
| 161 | 20년 전 | 2764 | ||
| 160 | 20년 전 | 1713 | ||
| 159 | 20년 전 | 1589 | ||
| 158 | 20년 전 | 2542 | ||
| 157 | 20년 전 | 1468 | ||
| 156 | 20년 전 | 1711 | ||
| 155 | 20년 전 | 3218 | ||
| 154 | 20년 전 | 1871 | ||
| 153 | 20년 전 | 1603 | ||
| 152 | 20년 전 | 4929 | ||
| 151 | 20년 전 | 4559 | ||
| 150 | 20년 전 | 3498 | ||
| 149 | 20년 전 | 3770 | ||
| 148 | 20년 전 | 7048 | ||
| 147 | 20년 전 | 3532 | ||
| 146 | 20년 전 | 2598 | ||
| 145 | 20년 전 | 2597 | ||
| 144 | 20년 전 | 7155 | ||
| 143 | 20년 전 | 4575 | ||
| 142 | 20년 전 | 1885 | ||
| 141 | 20년 전 | 3242 | ||
| 140 | 20년 전 | 1940 | ||
| 139 | 20년 전 | 1534 | ||
| 138 | 20년 전 | 2283 | ||
| 137 | 20년 전 | 1765 | ||
| 136 | 20년 전 | 1440 | ||
| 135 | 20년 전 | 1777 | ||
| 134 | 20년 전 | 2952 | ||
| 133 | 20년 전 | 2427 | ||
| 132 | 20년 전 | 1701 | ||
| 131 | 20년 전 | 1629 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기