Forum Moderators: open

Message Too Old, No Replies

code for a button to open an appended URL

         

ozwebadmin

4:38 am on Feb 10, 2005 (gmt 0)

10+ Year Member



I have a quick question. On a page on my site I intend to have a text box and a button which will take the contents of the text box and add them to the end of a URL and open the appended URL in a new window. How would I go about doing this?

rocknbil

5:42 pm on Feb 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well this should be **optional** content only because it will be completely Javascript-dependent. But this works. By the way, DEFINATELY change the URL's - ther really is an example.com out there.

<html><head><title></title></head>
<body>
<form>
<input type="text" name="whatever" size="20" maxlength="50" value="Green Widgets">
<input type="button" onClick="sendTo(this.form.whatever.value,400,500);" value="Go There">
</form>
<script language="javascript">
function sendTo(new_url,w,h) {
var url = 'http://www.example.com/script.cgi?selected='
var day = new Date;
var id = day.getTime();
var params = 'width='+w+',height='+h+',scrollbars,resizable';
url += escape(new_url);
//alert(url); // Un-comment this to verify it's working with alert box. It is.
var win = open(url,id,params);
}
</script>

</body>
</html>

ozwebadmin

5:06 am on Feb 11, 2005 (gmt 0)

10+ Year Member



Thanks fot that. That worked a treat. Changed the text box size a little to make it fit.