homepage Welcome to WebmasterWorld Guest from 54.196.195.158
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / HTML
Forum Library, Charter, Moderators: incrediBILL

HTML Forum

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




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

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?

 

toadhall




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

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;//***
window.open(sendhere);
}
</script>

In the <body> a simple form...

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

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.

T

ShawnR




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

"...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 = )

Shawn

vaxop




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

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 :(

ShawnR




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

"...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/' +....">

vaxop




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

i see

so how can i do it with js :)

the code above doesnt work for me

ggrot




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

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.

ShawnR




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

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;
}
-->
</script>

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');">
</form>

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / HTML
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved