Friday, December 28, 2012

onsubmit

Event handler onsubmit (Bubbles: No, Cancelable: Yes) terjadi ketika tombol Submit ditekan di dalam elemen FORM, dan terjadinya sebelum data-data di dalam elemen FORM dikirim kepada server.

Berikut contoh meregister event handler onsubmit via 'inline model':

<P>Log-In:</P> <FORM ONSUBMIT="alert('Anda mengirim data')"> Nama:<INPUT TYPE="text"> Password:<INPUT TYPE="password"> <INPUT TYPE="submit" VALUE="Submit"> </FORM>

Berikut contoh meregister event handler onsubmit via 'traditional model':

<P>Log-In:</P> <FORM ID="formID"> Nama:<INPUT TYPE="text"> Password:<INPUT TYPE="password"> <INPUT TYPE="submit" VALUE="Submit"> </FORM> <SCRIPT TYPE="text/javascript"> function HandleEvent() { alert('Anda mengirim data'); } document.getElementById("formID").onsubmit=HandleEvent; </SCRIPT>

Berikut contoh meregister event handler onsubmit via DOM:

<P>Log-In:</P> <FORM ID="formID"> Nama:<INPUT TYPE="text"> Password:<INPUT TYPE="password"> <INPUT TYPE="submit" VALUE="Submit"> </FORM> <SCRIPT TYPE="text/javascript"> function HandleEvent() { alert('Anda mengirim data'); } var formElem=document.getElementById("formID"); formElem.addEventListener("submit", HandleEvent, false); </SCRIPT>