0

Not sure if I can do this but I'm reading through JavaScript: The Definitive Guide, and I'm going to be posting practice scripts that work. They may not make sense, but they work.

I'd also like responses on how these simple snippets could be used and how they can be made better.

Opening a Window
This is just a simple form with an input box and a "Go" Button. You type in the URL that you want loaded into the new window. Click Go and a new Window Object is created and new window opened. I think.

HTML

<form name="frm">
<input name="website" type="text" size="40" maxlength="80" value="type url">

<input name="openpage" type="button" value="Go" onClick="goToPage()">
</form>

JavaScript

function goToPage() {
    var siteForm = document.getElementsByName("frm")[0];
    var webpage = siteForm.website.value;
    window.open(webpage);

    /* Works! */
    };
function goToPage() {
	var siteForm = document.getElementsByName("frm")[0];
	var webpage = siteForm.website.value;
	window.open(webpage);
	
	/* Works! */
	};
	
<form name="frm">
<input name="website" type="text" size="40" maxlength="80" value="type url">

<input name="openpage" type="button" value="Go" onClick="goToPage()">
</form>
2
Contributors
1
Reply
9
Views
5 Years
Discussion Span
Last Post by LastMitch
0

I'd also like responses on how these simple snippets could be used and how they can be made better.

It does open window but the url doesn't appear.

I not sure what you are doing.

I attached an image of how it looks like:

3972aba9e0b600ba34ac707e02f438a1

Edited by LastMitch: image

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.