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이상부터는 제공합니다
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 430 | 19년 전 | 4084 | ||
| 429 | 19년 전 | 3278 | ||
| 428 | 19년 전 | 4112 | ||
| 427 | 19년 전 | 3456 | ||
| 426 | 19년 전 | 3087 | ||
| 425 | 19년 전 | 3383 | ||
| 424 | 19년 전 | 2427 | ||
| 423 | 19년 전 | 2834 | ||
| 422 | 19년 전 | 2328 | ||
| 421 | 19년 전 | 3692 | ||
| 420 | 19년 전 | 4722 | ||
| 419 | 19년 전 | 3761 | ||
| 418 |
|
19년 전 | 1719 | |
| 417 | 19년 전 | 2727 | ||
| 416 | 19년 전 | 2370 | ||
| 415 | 19년 전 | 2598 | ||
| 414 | 19년 전 | 4390 | ||
| 413 |
|
19년 전 | 2562 | |
| 412 | 19년 전 | 3020 | ||
| 411 |
|
19년 전 | 2974 | |
| 410 |
|
19년 전 | 3652 | |
| 409 |
|
19년 전 | 3609 | |
| 408 |
|
19년 전 | 1828 | |
| 407 | 19년 전 | 2198 | ||
| 406 | 19년 전 | 2759 | ||
| 405 | 19년 전 | 2427 | ||
| 404 | 19년 전 | 4287 | ||
| 403 | 19년 전 | 3284 | ||
| 402 |
NeoGenesis
|
19년 전 | 4069 | |
| 401 | 19년 전 | 2583 | ||
| 400 |
|
19년 전 | 2467 | |
| 399 | 19년 전 | 2937 | ||
| 398 | 19년 전 | 2466 | ||
| 397 | 19년 전 | 2768 | ||
| 396 | 19년 전 | 2457 | ||
| 395 | 19년 전 | 3164 | ||
| 394 | 19년 전 | 1684 | ||
| 393 | 19년 전 | 2976 | ||
| 392 | 19년 전 | 2235 | ||
| 391 | 19년 전 | 2167 | ||
| 390 | 19년 전 | 2259 | ||
| 389 | 19년 전 | 2616 | ||
| 388 | 19년 전 | 2110 | ||
| 387 | 19년 전 | 4453 | ||
| 386 |
|
19년 전 | 2664 | |
| 385 |
|
19년 전 | 2446 | |
| 384 | 19년 전 | 2956 | ||
| 383 | 19년 전 | 3034 | ||
| 382 | 19년 전 | 3087 | ||
| 381 |
|
19년 전 | 2620 | |
| 380 |
|
19년 전 | 2997 | |
| 379 | 19년 전 | 2531 | ||
| 378 | 19년 전 | 2186 | ||
| 377 | 19년 전 | 2766 | ||
| 376 | 19년 전 | 2459 | ||
| 375 |
|
19년 전 | 2537 | |
| 374 | 19년 전 | 3787 | ||
| 373 | 19년 전 | 3251 | ||
| 372 | 19년 전 | 4972 | ||
| 371 |
세은아빠2
|
19년 전 | 2396 | |
| 370 | 19년 전 | 4488 | ||
| 369 | 19년 전 | 3089 | ||
| 368 | 19년 전 | 2871 | ||
| 367 | 19년 전 | 3711 | ||
| 366 | 19년 전 | 2625 | ||
| 365 | 19년 전 | 3709 | ||
| 364 | 19년 전 | 3983 | ||
| 363 | 19년 전 | 3413 | ||
| 362 | 19년 전 | 3464 | ||
| 361 | 19년 전 | 4085 | ||
| 360 |
hwatta
|
19년 전 | 2337 | |
| 359 | 19년 전 | 5072 | ||
| 358 | 19년 전 | 3628 | ||
| 357 | 19년 전 | 2575 | ||
| 356 |
sdesign1s
|
19년 전 | 2254 | |
| 355 | 20년 전 | 2717 | ||
| 354 | 20년 전 | 3011 | ||
| 353 | 20년 전 | 2779 | ||
| 352 |
|
20년 전 | 5760 | |
| 351 |
|
20년 전 | 2681 | |
| 350 |
|
20년 전 | 4262 | |
| 349 |
hwatta
|
20년 전 | 2151 | |
| 348 | 20년 전 | 7294 | ||
| 347 | 20년 전 | 2400 | ||
| 346 | 20년 전 | 3467 | ||
| 345 | 20년 전 | 4278 | ||
| 344 | 20년 전 | 2602 | ||
| 343 | 20년 전 | 3887 | ||
| 342 | 20년 전 | 3045 | ||
| 341 | 20년 전 | 4068 | ||
| 340 |
|
20년 전 | 5100 | |
| 339 |
|
20년 전 | 4208 | |
| 338 | 20년 전 | 5832 | ||
| 337 | 20년 전 | 2017 | ||
| 336 |
|
20년 전 | 3288 | |
| 335 |
|
20년 전 | 3521 | |
| 334 |
|
20년 전 | 2900 | |
| 333 |
hwatta
|
20년 전 | 2409 | |
| 332 | 20년 전 | 4639 | ||
| 331 | 20년 전 | 2251 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기