55
document.forms[0].field.select document.forms[0].field.focus
} script
head body
form input type=text name=field size=30 value=input text
input type=button value=Selected onclick=setfocus form
body html
7. Menggunakan tombol radio
html head
script type=textjavascript function checkbrowser
{ document.forms[0].answer.value=browser
} script
head body
form Which browser is your favoritebr
input type=radio name=browser onclick=checkthis.value value=Explorer
Microsoft Internet Explorerbr input type=radio name=browser onclick=checkthis.value
value=Netscape Netscape Navigatorbr
input type=text name=answer form
body html
8. Menggunakan kotak cek
html head
script type=textjavascript function check
{ coffee=document.forms[0].coffee
answer=document.forms[0].answer txt=
for i = 0; icoffee.length; ++ i {
if coffee[i].checked {
56
txt=txt + coffee[i].value + }
} answer.value=You ordered a coffee with + txt
} script
head body
form How would you like your coffee?br
input type=checkbox name=coffee value=creamWith creambr input type=checkbox name=coffee value=sugarWith sugarbr
input type=text name=answer size=30 input type=button name=test onclick=check value=Order
form body
html
9. Menggunakan kotak drop-down
html head
script type=textjavascript function put
{ option=document.forms[0].dropdown.options[document.forms[0].dropdown.selec
tedIndex].text txt=option
document.forms[0].favorite.value=txt }
script head
body form
p Select your favorite browser:
select name=dropdown onchange=put optionInternet Explorer
optionNetscape Navigator select
p p
Your favorite browser is: input type=text name=favorite value=Internet Explorer
p form
body html
10. Kotak drop-down sebagai menu
html
57
head script type=textjavascript
function goform {
location=form.selectmenu.value }
script head
body form
select name=selectmenu onchange=gothis.form option--Select page--
option value=http:www.telkom.netTelkomNet option value=http:www.google.comGoogle
option value=http:www.uad.ac.idUAD select
form body
html
11. Kotak teks yang otomatis berpindah fokus bila batasan masukan terpenuhi
html head
script type=textjavascript function toUnicodeelmnt,content
{ if content.length==elmnt.maxLength
{ next=elmnt.tabIndex
if
nextdocument.forms[0].elements.length {
document.forms[0].elements[next].focus }
} }
script head
body pThis script automatically sets focus to the next input field when the current
input fields maxlength has been reachedp form name=myForm
input size=3 tabindex=1 name=myInput maxlength=3 onkeyup=toUnicodethis,this.value
input size=3 tabindex=2 name=mySecond maxlength=3 onkeyup=toUnicodethis,this.value
input size=3 tabindex=3 name=myThird maxlength=3 onkeyup=toUnicodethis,this.value
form body
html
58
12. Deteksi browser yang digunakan