Forum Moderators: open
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?
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
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
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/' +....">
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...