java script 계산기를 홈피 적용에 문제가... 정보
java script 계산기를 홈피 적용에 문제가...본문
처음에 값을 입력하고 바로 계산하기를 누르면 엉뚱한 값이 나옵니다.
원인이 뭔가요??? 아무리 찾아도 눈에 들어오지를 않네요. -..-
댓글 전체
/* default unit */
unitCalcDisplay("length", "인치", "센티미터", "");
unitCalcDisplay("weight", "킬로그램", "파운드", "");
unitCalcDisplay("area", "평방미터", "평", "");
unitCalcDisplay("volume", "리터", "입방미터", "");
unitCalcDisplay("pressure", "Pa", "mmHg", "");
unitCalcDisplay("temperature", "섭씨온도", "화씨온도", "");
init 되고나서 선택되어져야 할 기본단위인데 select를 layer 로 만들어놔서 제대로 선택되지 않는겁니다.
단위를 선택하고나서 해보세요.
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;
}
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;
}