私は非常に新しいJavascriptでしかし、私は通貨コンバータを作成することを試みているhtml selectを使用して、素晴らしいことですが、関数を呼び出すと、ifステートメントをまっすぐにelse {}ステートメント通貨コンバータ! (Ifステートメント)
function convUSD()
{
RATE_GBP = 0.632111252;
RATE_EURO = 0.746435769;
RATE_AUD = 0.92945441;
if(document.selectBox.slBoxCurrency.selectedIndex == 0 && document.frmCurrencyC.radioUSD.checked)
{
window.alert("Sorry cant do USD to USD convertion! Please select another value.");
}
else if(document.selectBox.slBoxCurrency.selectedIndex == 0 && document.frmCurrencyC.radioGBP.checked)
{
inputBox = parseFloat(document.frmCurrencyC.textInputNum.value);
outPutBox = inputBox * RATE_GBP;
document.frmCurrencyC.textOutPutTotal.value = outPutBox;
}
else if(document.selectBox.slBoxCurrency.selectedIndex == 0 && document.frmCurrencyC.radioEURO.checked)
{
inputBox = parseFloat(document.frmCurrencyC.textInputNum.value);
outPutBox = inputBox * RATE_EURO;
document.frmCurrencyC.textOutPutTotal.value = outPutBox;
}
else if(document.selectBox.slBoxCurrency.selectedIndex == 0 && document.frmCurrencyC.radioAUD.checked)
{
inputBox = parseFloat(document.frmCurrencyC.textInputNum.value);
outPutBox = inputBox * RATE_AUD;
document.frmCurrencyC.textOutPutTotal.value = outPutBox;
}
else
{
window.alert("Whoops there was an error");
}
}
最初、私は実際にそれがストレートelseステートメントに向かうGBPに例のUSDのために何をしたいとき文がしかし、正常に動作している場合。
もしあなたが何らかのエラーを発見した場合、あるいは何かがうまくいけばそれは大いに感謝します。
をHTMLフォームこのコードリファレンスを投稿してください。できる場合は、http://jsfiddle.netに投稿してください –
http://jsfiddle.net/X8MyF/完全なhtml/jsコード、ありがとうございます – JayJsNewbie
ほとんどすべてのコードは冗長です。最初に、 'selectedIndex'をチェックしてください。非ゼロの場合は終了します。次に、チェックボックスがオンになっているコンバージョン率を把握します。テキストを解析し、変換レートを掛けて、それを吐き出す。 –