Make this a Shortcut

You might have noticed that the <form> tag in ❶ of Figure 7-25 is a little long. You can shorten it by replacing most of the part identifying the form, window.document.the_form, with the word this, which refers to the thing that contains it. For example, in ❶ of Figure 7-25, the code that looks for the value of the_url is located inside the <form> tag. That means you can replace all the code identifying the <form> tag with the word this—in other words, you can write ❶ in Figure 7-25 as follows:

<form name = "the_form" onSubmit = "window.location = this.the_url.value;">

I've replaced the elements that identify the form, window.document.the_form, with this, because this is inside the <form> tag. Though it's sometimes hard to know ...

Get The Book of JavaScript, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.