자바 스크립트 이거 제대로 짯는지 좀 봐주세요... 정보
자바 스크립트 이거 제대로 짯는지 좀 봐주세요...
본문
막 중복에 엉망징창으로 짜여진 소스 일겁니다.
그치만 일단 99% 구동은 되는데.. 딱 하나가 안되서.. 소스를 어떻게 올려야할지 모르겠네요..
일단 아래 소스구요..
나름대로 주석도 넣었는데..
모든 기능은 잘되는데.. 포인트 넣는부분 point_price 요것을 본인의 보유포인트보다 적게 입력하면 합계가 nan으로 되네요..
수량을 올리거나 내리면 합계가 자동을 원래대로 계산이 되구요..
엉뚱하게 짠 소스지만... 정말로 다른 기능은 다 잘됩니다.. ^^;;
흠.. 펑션함수 넣은부분을 설명하자면..
init()는 바디에 onload="init();" 시켰구요..
add()는 수량을 올리는 버튼에 onclick="add()'로 넣었구요..
del()는 수량을 내리는 버튼에 onclick="del()'로 넣었어요..
change()는 수량 인풋박스에 onchange="change();" 로 넣었고..
point()는 포인트 입력인풋박스에 onchange="point();" 로 넣었습니다.
이것만으로 잘못된걸 알 수 있을까요??
내부 다른 php 소스도 필요하다면 말씀해주세요..
보여드릴께요...
=================================================================================
<script language="JavaScript">
<!--
var wr_3; //판매가
var wr_2; //수량
function init () {
wr_3 = document.fwrite.wr_3.value; //판매가
wr_2 = document.fwrite.wr_2.value; //수량
//point_price = document.fwrite.point_price; //포인트할인
change();
}
wr_3 = document.fwrite.wr_3.value; //판매가
wr_2 = document.fwrite.wr_2.value; //수량
//point_price = document.fwrite.point_price; //포인트할인
change();
}
function add () {
hm = document.fwrite.wr_2; //수량
price1 = document.fwrite.price1; //주문합계
point_price = document.fwrite.point_price; //포인트할인
sum_price = document.fwrite.sum_price; // 주문합계 [제품가 + 옵션가]
sum_price2 = document.fwrite.sum_price2; // 배송비계산에 필요 [주문합계 - 포인트할인]
wr_9 = document.fwrite.wr_9; //총합계
price2 = document.fwrite.price2; //배송비
//hm.value ++ ;
if (hm.value < <?=$inventory?>) {
hm.value ++ ;
price1.value = eval(parseInt(hm.value) * parseInt(sum_price.value));
} else {
alert ('<?=$inventory?>개 이상 주문하실 수 없습니다.');
}
if (<?=$profile[mb_point]?> < parseInt(point_price.value)) {
alert("보유하신 포인트보다 많은 할인을 받을 수 없습니다.");
point_price.value = <?=$profile[mb_point]?>;
}
sum_price2.value = eval(parseInt(price1.value) - parseInt(point_price.value));
if (sum_price2.value < 60000) { // 무료배송 6만원부터
price2.value = 3000;
} else {
price2.value = 0;
}
wr_9.value = eval(parseInt(sum_price2.value) + parseInt(price2.value));
}
hm = document.fwrite.wr_2; //수량
price1 = document.fwrite.price1; //주문합계
point_price = document.fwrite.point_price; //포인트할인
sum_price = document.fwrite.sum_price; // 주문합계 [제품가 + 옵션가]
sum_price2 = document.fwrite.sum_price2; // 배송비계산에 필요 [주문합계 - 포인트할인]
wr_9 = document.fwrite.wr_9; //총합계
price2 = document.fwrite.price2; //배송비
//hm.value ++ ;
if (hm.value < <?=$inventory?>) {
hm.value ++ ;
price1.value = eval(parseInt(hm.value) * parseInt(sum_price.value));
} else {
alert ('<?=$inventory?>개 이상 주문하실 수 없습니다.');
}
if (<?=$profile[mb_point]?> < parseInt(point_price.value)) {
alert("보유하신 포인트보다 많은 할인을 받을 수 없습니다.");
point_price.value = <?=$profile[mb_point]?>;
}
sum_price2.value = eval(parseInt(price1.value) - parseInt(point_price.value));
if (sum_price2.value < 60000) { // 무료배송 6만원부터
price2.value = 3000;
} else {
price2.value = 0;
}
wr_9.value = eval(parseInt(sum_price2.value) + parseInt(price2.value));
}
function del () {
hm = document.fwrite.wr_2; //수량
price1 = document.fwrite.price1; //주문합계
point_price = document.fwrite.point_price; //포인트할인
sum_price = document.fwrite.sum_price; // 주문합계 [제품가 + 옵션가]
sum_price2 = document.fwrite.sum_price2; // 배송비계산에 필요 [주문합계 - 포인트할인]
wr_9 = document.fwrite.wr_9; //총합계
price2 = document.fwrite.price2; //배송비
if (hm.value > 1) {
hm.value -- ;
price1.value = eval(parseInt(hm.value) * parseInt(sum_price.value));
}
if (<?=$profile[mb_point]?> < parseInt(point_price.value)) {
alert("보유하신 포인트보다 많은 할인을 받을 수 없습니다.");
point_price.value = <?=$profile[mb_point]?>;
}
sum_price2.value = eval(parseInt(price1.value) - parseInt(point_price.value));
if (sum_price2.value < 60000) { // 무료배송 6만원부터
price2.value = 3000;
} else {
price2.value = 0;
}
wr_9.value = eval(parseInt(sum_price2.value) + parseInt(price2.value));
}
hm = document.fwrite.wr_2; //수량
price1 = document.fwrite.price1; //주문합계
point_price = document.fwrite.point_price; //포인트할인
sum_price = document.fwrite.sum_price; // 주문합계 [제품가 + 옵션가]
sum_price2 = document.fwrite.sum_price2; // 배송비계산에 필요 [주문합계 - 포인트할인]
wr_9 = document.fwrite.wr_9; //총합계
price2 = document.fwrite.price2; //배송비
if (hm.value > 1) {
hm.value -- ;
price1.value = eval(parseInt(hm.value) * parseInt(sum_price.value));
}
if (<?=$profile[mb_point]?> < parseInt(point_price.value)) {
alert("보유하신 포인트보다 많은 할인을 받을 수 없습니다.");
point_price.value = <?=$profile[mb_point]?>;
}
sum_price2.value = eval(parseInt(price1.value) - parseInt(point_price.value));
if (sum_price2.value < 60000) { // 무료배송 6만원부터
price2.value = 3000;
} else {
price2.value = 0;
}
wr_9.value = eval(parseInt(sum_price2.value) + parseInt(price2.value));
}
function change () {
hm = document.fwrite.wr_2; //수량
price1 = document.fwrite.price1; //주문합계
point_price = document.fwrite.point_price; //포인트할인
sum_price = document.fwrite.sum_price; // 주문합계 [제품가 + 옵션가]
sum_price2 = document.fwrite.sum_price2; // 배송비계산에 필요 [주문합계 - 포인트할인]
wr_9 = document.fwrite.wr_9; //총합계
price2 = document.fwrite.price2; //배송비
hm = document.fwrite.wr_2; //수량
price1 = document.fwrite.price1; //주문합계
point_price = document.fwrite.point_price; //포인트할인
sum_price = document.fwrite.sum_price; // 주문합계 [제품가 + 옵션가]
sum_price2 = document.fwrite.sum_price2; // 배송비계산에 필요 [주문합계 - 포인트할인]
wr_9 = document.fwrite.wr_9; //총합계
price2 = document.fwrite.price2; //배송비
if (hm.value < 0) {
hm.value = 0;
}
price1.value = eval(parseInt(hm.value) * parseInt(sum_price.value));
if (<?=$profile[mb_point]?> < parseInt(point_price.value)) {
alert("보유하신 포인트보다 많은 할인을 받을 수 없습니다.");
point_price.value = <?=$profile[mb_point]?>;
}
sum_price2.value = eval(parseInt(price1.value) - parseInt(point_price.value));
if (sum_price2.value < 60000) { // 무료배송 6만원부터
price2.value = 3000;
} else {
price2.value = 0;
}
wr_9.value = eval(parseInt(sum_price2.value) + parseInt(price2.value));
}
function point() {
hm = document.fwrite.wr_2; //수량
price1 = document.fwrite.price1; //주문합계
point_price = document.fwrite.point_price; //포인트할인
sum_price = document.fwrite.sum_price; // 주문합계 [제품가 + 옵션가]
sum_price2 = document.fwrite.sum_price2; // 배송비계산에 필요 [주문합계 - 포인트할인]
wr_9 = document.fwrite.wr_9; //총합계
price2 = document.fwrite.price2; //배송비
hm.value = 0;
}
price1.value = eval(parseInt(hm.value) * parseInt(sum_price.value));
if (<?=$profile[mb_point]?> < parseInt(point_price.value)) {
alert("보유하신 포인트보다 많은 할인을 받을 수 없습니다.");
point_price.value = <?=$profile[mb_point]?>;
}
sum_price2.value = eval(parseInt(price1.value) - parseInt(point_price.value));
if (sum_price2.value < 60000) { // 무료배송 6만원부터
price2.value = 3000;
} else {
price2.value = 0;
}
wr_9.value = eval(parseInt(sum_price2.value) + parseInt(price2.value));
}
function point() {
hm = document.fwrite.wr_2; //수량
price1 = document.fwrite.price1; //주문합계
point_price = document.fwrite.point_price; //포인트할인
sum_price = document.fwrite.sum_price; // 주문합계 [제품가 + 옵션가]
sum_price2 = document.fwrite.sum_price2; // 배송비계산에 필요 [주문합계 - 포인트할인]
wr_9 = document.fwrite.wr_9; //총합계
price2 = document.fwrite.price2; //배송비
price1 = eval(parseInt(hm.value) * parseInt(sum_price.value));
if (<?=$profile[mb_point]?> < parseInt(point_price.value)) {
alert("보유하신 포인트보다 많은 할인을 받을 수 없습니다.");
point_price.value = <?=$profile[mb_point]?>;
}
sum_price2.value = eval(parseInt(price1.value) - parseInt(point_price.value));
if (sum_price2.value < 60000) { // 무료배송 6만원부터
price2.value = 3000;
} else {
price2.value = 0;
}
wr_9.value = eval(parseInt(sum_price2.value) + parseInt(price2.value));
}
//-->
</script>
if (<?=$profile[mb_point]?> < parseInt(point_price.value)) {
alert("보유하신 포인트보다 많은 할인을 받을 수 없습니다.");
point_price.value = <?=$profile[mb_point]?>;
}
sum_price2.value = eval(parseInt(price1.value) - parseInt(point_price.value));
if (sum_price2.value < 60000) { // 무료배송 6만원부터
price2.value = 3000;
} else {
price2.value = 0;
}
wr_9.value = eval(parseInt(sum_price2.value) + parseInt(price2.value));
}
//-->
</script>
댓글 전체
60000 같은 금액 부분이 너무 하드코딩 되어 잇지 않나요? 나중에 수정하려면 힘들꺼 같아요
으억!! 그렇죠~ 으흐.. 건 수정했습니다!! ^^*
근데.. 암두 안봐주네요.. 흑흑! 버그 어쩌지~~ ㅠㅁㅠ
근데.. 암두 안봐주네요.. 흑흑! 버그 어쩌지~~ ㅠㅁㅠ
잘만드셨도용.....
으흑!! 다시 질문할래요~~