Released: 12/27/2004
DOWNLOAD CODE FOR THIS ANSWER
Question:
I'm totally new in this programming business and I need some help from you guys. I'm trying to create this simple text input field which allows user to key in a name, followed by clicking a button, the page launches.

I've only managed to figure out this for the past one hour of reading through some websites.

<form>

User Name : <input type="text" name="name" size="35">
<p>
<input type="button" value="Open Window" onclick="window.open('http://www.geocities.com/)">
</p>
</form>

So the launched window should be http://www.geocities.com/xxxxxxxxxx

xxxxxxxxxxx being whatever name you typed in the box, how do I assign this variable to incorporate into my code ? can anyone help please?
Answer:
There are many ways to do this.
Here is but one of them:

FOR DEMO CLICK HERE (should work in Firefox IE and Netscape)
 
Code:
<HTML>
<HEAD>
<TITLE>Open Window from input value</TITLE>
<SCRIPT>
function openIT()
{
windowURL=document.getElementById('idHERE').value
window.open(windowURL)
}
</SCRIPT>
</HEAD>
<BODY>
Window Location : <input type="text" id="idHERE" value="http://" size="35">
<p><input type="button" value="Open Window" onclick="openIT()"></p>
</BODY>
</HTML>
Explanation:
When the user clicks on the button openIT() routine runs.
In the first line "windowURL=document.getElementById('idHERE').value"
the value of the input box with the id of "idHERE" is given to windowURL.
This variable is then used in the second line to open the window.

 

Top of Page

Valid HTML 4.01!

Views: 271

Valid CSS!