Length Converter Script
ออกแบบโดย Howard Chen
คำอธิบาย : เป็นโปรแกรมคำนวณความยาวต่าง ๆ
ตัวอย่างการใช้งาน UnitNumber Centimeter Meter Kilometer Inch Foot Yard Mile Centimeter: Meter: Kilometer: Inch: Foot: Yard: Mile:
ขั้นตอนที่ 1: นำสคริปต์ข้างล่างนี้ใส่ไว้ในส่วน <head> ของเว็บเพจ
เลือกข้อความทั้งหมด <SCRIPT> <!-- // Script Editor: Howard Chen // Browser Compatible for the script: IE 2.0 or Higher // Netscape 2.0 or Higher // This script is free as long as you keep its credits /*The way this works is the converter converts the number into the smallest unit in the converter, in this case it will be centimeter, and then it converts the unit fram centimeterto other units.*/ function nofocus() { document.convert.InUnit.focus() } var cmValue = 1 var mValue = 100 var kmValue = 100000 var inValue = 2.54000843476 var ftValue = 30.4801012183 var ydValue = 91.440275784 var miValue = 1609.34708789 function toCM() { var i = document.convert.unit.selectedIndex var thisUnit = document.convert.unit.options[i].value if (thisUnit == "CM") { document.convert.cm.value = document.convert.InUnit.value } else if(thisUnit == "M") { document.convert.cm.value = document.convert.InUnit.value * mValue } else if(thisUnit == "KM" ) { document.convert.cm.value = document.convert.InUnit.value * kmValue } else if(thisUnit == "IN" ) { document.convert.cm.value = document.convert.InUnit.value * inValue } else if(thisUnit == "FT" ) { document.convert.cm.value = document.convert.InUnit.value * ftValue } else if(thisUnit == "YD" ) { document.convert.cm.value = document.convert.InUnit.value * ydValue } else if(thisUnit == "MI" ) { document.convert.cm.value = document.convert.InUnit.value * miValue } toAll() } function toAll() { var m = document.convert.cm.value document.convert.m.value = m / mValue document.convert.km.value = m / kmValue document.convert.inch.value = m / inValue document.convert.ft.value = m / ftValue document.convert.yd.value = m / ydValue document.convert.mi.value = m / miValue } //--> </SCRIPT>
ขั้นตอนที่ 2: นำโค้ดส่วนที่ 2 ใส่ไว้ใน <body> ของเว็บเพจ
เลือกข้อความทั้งหมด <FORM NAME="convert"> <TABLE BORDER=1> <TR><TH>Unit</TH><TH>Number</TH></TR> <TR> <TD> <SELECT NAME="unit"> <OPTION VALUE = "CM">Centimeter <OPTION VALUE = "M">Meter <OPTION VALUE = "KM">Kilometer <OPTION VALUE = "IN">Inch <OPTION VALUE = "FT">Foot <OPTION VALUE = "YD">Yard <OPTION VALUE = "MI">Mile </SELECT> </TD> <TD> <INPUT TYPE="text" NAME="InUnit" SIZE="20" MAXLENGTH="20" VALUE="0"> </TD> </TR> <TR> <TD> Centimeter: </TD> <TD> <INPUT TYPE="text" NAME="cm" SIZE="20" MAXLENGTH="20" VALUE="0" onFocus="nofocus()"> </TD> </TR> <TR> <TD> Meter: </TD> <TD> <INPUT TYPE="text" NAME="m" SIZE="20" MAXLENGTH="20" VALUE="0" onFocus="nofocus()"> </TD> </TR> <TR> <TD> Kilometer: </TD> <TD> <INPUT TYPE="text" NAME="km" SIZE="20" MAXLENGTH="20" VALUE="0" onFocus="nofocus()"> </TD> </TR> <TR> <TD> Inch: </TD> <TD> <INPUT TYPE="text" NAME="inch" SIZE="20" MAXLENGTH="20" VALUE="0" onFocus="nofocus()"> </TD> </TR> <TR> <TD> Foot: </TD> <TD> <INPUT TYPE="text" NAME="ft" SIZE="20" MAXLENGTH="20" VALUE="0" onFocus="nofocus()"> </TD> </TR> <TR> <TD> Yard: </TD> <TD> <INPUT TYPE="text" NAME="yd" SIZE="20" MAXLENGTH="20" VALUE="0" onFocus="nofocus()"> </TD> </TR> <TR> <TD> Mile: </TD> <TD> <INPUT TYPE="text" NAME="mi" SIZE="20" MAXLENGTH="20" VALUE="0" onFocus="nofocus()"> </TD> </TR> <TR> <TD> <INPUT TYPE="Reset" VALUE="Start Over" WIDTH=100> </TD> <TD> <INPUT TYPE="button" VALUE="Convert" onClick="toCM()" WIDTH=150> </TD> </TR> </TABLE> </FORM>