Practice Scripts - Opening a Window

FutureWebDev 0 Tallied Votes 230 Views Share

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>
Member Avatar for LastMitch
LastMitch

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.