Welcome to WebmasterWorld Guest from

Forum Moderators: incrediBILL

Message Too Old, No Replies

How to navigate to a site based on the value of a textbox?



11:30 pm on Jun 28, 2003 (gmt 0)

10+ Year Member

I dont have php, cgi, apache, or any of the other good things. Im running a very simple server that I coded in visual basic.

I cant pass any variables through to the server, so, i need to hope that dhtml can do what im trying to accomplish.

From a textbox and a submitbutton, how can i navigate the user to filename/path/VALUEOFTEXTBOX?

so if they put in "welcome", after pressing the submit button, they would be redirected to filename/path/welcome

anyone know?


2:26 am on Jun 29, 2003 (gmt 0)

10+ Year Member

This uses a bit of code from O'Reilly's Definitive Guide, the getargs() function. The rest is straight forward.

In the <head>...

<script language="JavaScript">
function getArgs() {
var args = new Object();
var query = location.search.substring(1); // Get query string.
var pairs = query.split("&");// Break at comma.
for(var i = 0; i < pairs.length; i++) {
var pos = pairs[i].indexOf('=');// Look for "name=value".
if (pos == -1) continue;// If not found, skip.
var argname = pairs[i].substring(0,pos); // Extract the name.
var value = pairs[i].substring(pos+1);// Extract the value.
args[argname] = unescape(value); // Store as a property.
return args;// Return the object.
//end of function
var args = getArgs();
if (args.name){
var name = args.name.toLowerCase();
var sendhere = "path/to/wherever/" + name;//***

In the <body> a simple form...

Name: <input type=text name=name><br>
<input type=submit>

Just substitute < path/to/wherever/ > with your path on the line marked //***

If 'name' is a directory you might use this line instead:
var sendhere = "path/to/wherever/" + name + "/";

Add some anti-caching and you're off.

Mods: Sorry if this is deemed a "doing someones homework" response but getArgs() is pretty unique and would take a month of Sundays to talk through.



2:58 am on Jun 29, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

"...Add some anti-caching and you're off..."

Toadhall, can you elaborate. Sorry if this is off-topic, but it looks relevant as it is part of the solution.

(BTW, another solution is just use the onclick() event of the form to call a function which exracts the contents of the text box, and does a window.open() or a window.location.href = )



4:54 am on Jun 29, 2003 (gmt 0)

10+ Year Member

im lost..

is it possible to do a non js version?

something like onlink=window.open("http://site.com/filename/path/" & document.forms[0].name.value)

but i dont know dhtml :(


5:22 am on Jun 29, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

"...is it possible to do a non js version...

If you can't use any server-side processing, the short answer is NO.

I think some terms need to be clarified... DHTML is not really well defined anywhere. It started life many years ago as a marketing term introduced by Microsoft to encourage the world to drop Java. (Thankfully the objective was never realised, but now we are stuck with the term.) It generally means a mixture of technologies like CSS, Javascript and the DOM, to produce a dynamic look and feel to websites. Why am I raising this? Because in your opening post you ask for a DHTML solution, yet in post # 4 you ask for a non-javascript solution, and ask for a solution instead which uses constructs like "window.forms...." i.e. which uses javascript code.

So could you explain why you don't want to use javascript? Is it that you are concerned about people with javascript turned off in their browsers, or is it that you don't want too much javascript but you're OK with a few in-line constructs, or some other reason?

BTW, I think what you are alluding to is what I was suggesting in messge # 3:
<input type=submit onclick="window.open('http://site.com/filename/path/' +....">


3:23 am on Jun 30, 2003 (gmt 0)

10+ Year Member

i see

so how can i do it with js :)

the code above doesnt work for me


4:47 am on Jun 30, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

onlink=window.open("http://site.com/filename/path/" & document.forms[0].name.value)

That is javascript code, turn off javascript and it wont work. DHTML is also just a fancy term for javascript.


7:58 am on Jun 30, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

There is no event called 'onlink', and there is no '&' operator (use '+' for concatenation in Javascript)

So here is what I suggest:
In the head section of the html page:

<script type="text/javascript">
function send_to_page(text_box_name) {
var my_text_box_contents = document.getElementById(text_box_name).value;
var full_desination = "path/to/wherever/" + my_text_box_contents;
alert(full_desination); // This line for debugging. Remove it when you are happy things work properly.
window.open(full_desination, "_self", "");
return false;

In the body section of the html page:

<form name="my_form_name" method="get" action="">
<input type="text" name="my_text_box">
<input type=submit onclick="send_to_page('my_text_box');">

Totally untested... So there may be errors. Post back with details of the errors, and someone will help...


Featured Threads

Hot Threads This Week

Hot Threads This Month