In the last part I explained a few of the things you can do using forms. In this, the final part, of the JavaScript tutorial I will explain how you can do some other things with your JavaScript forms.
Using The Submit Button
The most common use of forms is to submit data to a script so that it can be processed. This is fine if you are using CGI to do a mailto form or something like that, but if you just want to run a piece of JavaScript from a form you will need to do things a little differently. The first part you must learn about is the return false; attribute. It can be used as follows:
You can try it out below:
What this code does is tell the JavaScript that when the form is submitted it should do nothing. This stops Netscape from refreshing the page (as it would do if there was just a submit button and the form had no action). Now what you can do is to call a function using the submit button:
What this code is doing is, when the select is changed it is telling the page in the browser to change its location to the value of the select box. The location of the document is accessed using:
window.document.location
As you can see, this is could be very useful, both for getting feedback from visitors and for redirecting them (as in the example above).
Conclusion
In this tutorial I covered some of the most important parts of JavaScript and now you should be able to start writing some quite advanced scripts. There is still a lot of JavaScript left to learn with many more advanced commands. In the future I will do a tutorial on this. One way of improving your skills, though, is to look at the code of other people's pages that use JavaScript. Don't steal them but you can learn more about the language by doing this.
Sumber: Look
Using The Submit Button
The most common use of forms is to submit data to a script so that it can be processed. This is fine if you are using CGI to do a mailto form or something like that, but if you just want to run a piece of JavaScript from a form you will need to do things a little differently. The first part you must learn about is the return false; attribute. It can be used as follows:
You can try it out below:
What this code does is tell the JavaScript that when the form is submitted it should do nothing. This stops Netscape from refreshing the page (as it would do if there was just a submit button and the form had no action). Now what you can do is to call a function using the submit button:
What this code is doing is, when the select is changed it is telling the page in the browser to change its location to the value of the select box. The location of the document is accessed using:
window.document.location
As you can see, this is could be very useful, both for getting feedback from visitors and for redirecting them (as in the example above).
Conclusion
In this tutorial I covered some of the most important parts of JavaScript and now you should be able to start writing some quite advanced scripts. There is still a lot of JavaScript left to learn with many more advanced commands. In the future I will do a tutorial on this. One way of improving your skills, though, is to look at the code of other people's pages that use JavaScript. Don't steal them but you can learn more about the language by doing this.
Sumber: Look
0 comments :
Post a Comment
Bagi anda yang ingin meninggalkan komentar dan tidak memiliki Akun, silahkan gunakankan Anonymous.
Anda boleh mengcopy sebagian atau seluruh isi blog ini dengan tetap mencantumkan alamat blog.
Terima kasih telah berkunjung
salam Hangat dari Admin Aneka Raga