숫자값의 콤마찍기 재 질문 드립니다.
본문
아래는 콤마찍기전에 스크립 계산을 적용한 내용입니다.
계산은 잘되는데 문제는 출력값에 콤마가 안찍히네요.
구글링 해도 답이 없습니다.
<a onclick="setmony(100000); reduce()" >
<input name="a" type="text" value="0" readonly id="a" size="7" >
</a>
<a onclick="setmony2(500000); reduce()" >
<input name="b" type="text" value="0" readonly id="b" size="7" >
</a>
<a onclick="setmony3(1000000); reduce()" >
<input name="c" type="text" value="0" readonly id="c" size="7" >
</a>
<script language="JavaScript">
function setmony(i) {
var x = document.getElementById("a");
x.value = parseInt(x.value) + i;
}
</script>
<script language="JavaScript">
function setmony2(i) {
var x = document.getElementById("b");
x.value = parseInt(x.value) + i;
}
</script>
<script language="JavaScript">
function setmony3(i) {
var x = document.getElementById("c");
x.value = parseInt(x.value) + i;
}
</script>
<script language="JavaScript">
function reduce() {
var a = parseInt(document.getElementById('a').value) | 0;
var b = parseInt(document.getElementById('b').value) | 0;
var c = parseInt(document.getElementById('c').value) | 0;
document.getElementById('me_send_point2').value = a+b+c;
var reduce = value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")
}
</script>
<script language="JavaScript">
function setmony(i) {
var x = document.getElementById("a");
x.value = parseInt(x.value) + i;
var setmony = $('#a').text();
var setmony = setmony.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
</script>
--------------------------------------------------------------------------
아래는 합계값의 콤마 값인데 안되구요.
.replace(/\B(?=(\d{3})+(?!\d))/g, ",")
1번항목에 아래와 같이 줘도 안됩니다.
<script language="JavaScript">
function setmony(i) {
var x = document.getElementById("a");
x.value = parseInt(x.value) + i;
var setmony = $('#a').text();
var setmony = setmony.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
</script>
답변 2
<a onclick="setmony(100000); reduce()" >
<input name="a" type="text" value="0" readonly id="a" size="7" >
</a>
<a onclick="setmony2(500000); reduce()" >
<input name="b" type="text" value="0" readonly id="b" size="7" >
</a>
<a onclick="setmony3(1000000); reduce()" >
<input name="c" type="text" value="0" readonly id="c" size="7" >
</a>
me_send_point2 : <input id="me_send_point2">
<script language="JavaScript">
function setmony(i) {
var x = document.getElementById("a");
x.value = parseInt(x.value) + i;
}
</script>
<script language="JavaScript">
function setmony2(i) {
var x = document.getElementById("b");
x.value = parseInt(x.value) + i;
}
</script>
<script language="JavaScript">
function setmony3(i) {
var x = document.getElementById("c");
x.value = parseInt(x.value) + i;
}
</script>
<script language="JavaScript">
function reduce() {
var a = parseInt(document.getElementById('a').value) || 0;
var b = parseInt(document.getElementById('b').value) || 0;
var c = parseInt(document.getElementById('c').value) || 0;
var value = a+b+c;
var reduce = value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")
document.getElementById('me_send_point2').value = reduce;
}
</script>
코드가 어질어질 하네요...
계산완료 값이 리턴 될때 콤마 펑션을 넣으세요...