tags:

views:

49

answers:

2

Hi, I need some javascript that will provide a textbox for the user to supply a key, append a parameter to a URL and then open it in the current window.

Simple, I'm sure, but I'm new to Javascript.

Any help would certainly be appreciated!

Thanks!

+1  A: 

Depending on what action you want the user to take to trigger this, you could call this function which would accomplish the task.

HTML:

<input type="text" name="key" id="theTextBoxID" />

JS:

function changeLocation(){

    var theTextBox = document.getElementById("theTextBoxID");
    window.location = "someurl.html?someVariable="+theTextBox.value;

}

This function could be called by a submit action or an onclick event, etc...

a432511
A: 

If you had this HTML

<input type="text" name="url" id="url" />
<input type="submit" value="Open URL" onclick="open_url(); return false;" />

Then you would use this JavaScript

function open_url(){
   var url = document.getElementById('url');
   url = encodeURIComponent(url); // This escapes special characters

   window.location = 'http://yourdomain.com/?path=' + url; // Change the current url of the page
}

If you were redirecting to a page on the same server, you don't need the domain name or protocol in the window.location call.

Doug Neiner
Thank you both very very much! Exactly what I was looking for!
Betsy