java script 계산기를 홈피 적용에 문제가...

 
처음에 값을 입력하고 바로 계산하기를 누르면 엉뚱한 값이 나옵니다.
원인이 뭔가요??? 아무리 찾아도 눈에 들어오지를 않네요. -..-
|

댓글 2개

/* default unit */
unitCalcDisplay("length", "인치", "센티미터", "");
unitCalcDisplay("weight", "킬로그램", "파운드", "");
unitCalcDisplay("area", "평방미터", "평", "");
unitCalcDisplay("volume", "리터", "입방미터", "");
unitCalcDisplay("pressure", "Pa", "mmHg", "");
unitCalcDisplay("temperature", "섭씨온도", "화씨온도", "");

init 되고나서 선택되어져야 할 기본단위인데 select를 layer 로 만들어놔서 제대로 선택되지 않는겁니다.
단위를 선택하고나서 해보세요.
그러면 이부분의 프로그램에서 문제가 있는 것이네요. value가 ""인경우 (처음 초기화)
select box를 초기화된 값으로 바꿔줘야 하는데... 그것을 못한 것이네요. -..-a

unitCalcDisplay("length", "인치", "센티미터", ""); 와 같이 초기화를 할 때 ... 화면에
보이는 부분을 "인치", "센티미터"로 바꿔주면 되는데... 끙~ 끙~ 어딜 손대야 할지 참 난감한 코드네요.

for (i = 0; i < fromSelect.options.length; i++)
{
if (fromSelect.options[i].value == from)
fromSelect.selectedIndex = i;

if (toSelect.options[i].value == to)
toSelect.selectedIndex = i;
}

윗 부분에서 선택된거 같은데 뭐가 문제죠??? ..-.-

function unitCalcDisplay(type, from, to, value)
{
var i;
var fromSelect = document.getElementById("s_" + type + "From");
var toSelect = document.getElementById("s_" + type + "To");

if (from)
{
var valueText = document.getElementById(type + "Value");

if (!valueText || !fromSelect || !toSelect)
return;

valueText.value = value;

for (i = 0; i < fromSelect.options.length; i++)
{
if (fromSelect.options[i].value == from)
fromSelect.selectedIndex = i;

if (toSelect.options[i].value == to)
toSelect.selectedIndex = i;
}
}
else
{
value = document.getElementById(type + "Value").value;
from = fromSelect.options[fromSelect.selectedIndex].value;
to = toSelect.options[toSelect.selectedIndex].value;
}

if (!value || !from || !to) return;

var result = unitCalc(type, from, to, value);

document.getElementById(type + "Result").value = result;
}
댓글을 작성하시려면 로그인이 필요합니다. 로그인

그누4 질문답변

그누보드4 관련 질문은 QA 로 이전됩니다. QA 그누보드4 바로가기 기존 게시물은 열람만 가능합니다.

+
제목 글쓴이 날짜 조회
18년 전 조회 1,825
18년 전 조회 1,576
18년 전 조회 1,514
18년 전 조회 1,676
18년 전 조회 1,520
18년 전 조회 1,529
18년 전 조회 1,463
18년 전 조회 1,574
18년 전 조회 940
18년 전 조회 1,511
18년 전 조회 1,255
18년 전 조회 1,523
18년 전 조회 1,485
18년 전 조회 1.4만
18년 전 조회 1,446
18년 전 조회 1,510
18년 전 조회 1,933
18년 전 조회 1,457
18년 전 조회 1,511
18년 전 조회 1,679
🐛 버그신고