PDA

View Full Version : vars in address


rbmyr81
12-27-2003, 11:10 PM
hey i was wondering how to umm... use variables in the address... like this-

http://www.htmlforums.com/newthread.php?s=&action=newthread&forumid=6

say i wanted to make the value of.. oh say a text box named "txtbx" the value of "action" in the address..
so i would have a text box that said "newthread" but how do i do that(document.all.txtbx.value=action>????
obviously that don't work.. so how do i do that? and also does it work in html cuz thats the only launguage bsides javascript that i know :(

TIA-
BoB

agent002
12-28-2003, 08:41 AM
The best way is to use a serverside language, but JavaScript can do it too.
<html>
<head>
<title>Document title</title>
<script type="text/javascript"><!--

var query = location.href.substring((location.href.indexOf('?') + 1), location.href.indexOf('#'));
if(location.href.indexOf('#') < location.href.indexOf('?')){
query = location.href.substring((location.href.indexOf('?') + 1), location.href.length);
}
if(location.href.indexOf('?') < 0){
query = '';
}

function GetQuery(att){
var querysplit = query.split('&');
var ret = '';
for(var i = 0; i < querysplit.length; i++){
var namevalue = querysplit[i].split('=');
if(namevalue[0] && namevalue[1] && namevalue[0] == att){
ret = unescape(namevalue[1]);
}
}
return ret;
}

function loaded(){
document.getElementById('fillin').value = GetQuery('action');
}

window.onload = loaded;

--></script></head>
<body>

<input type="text" name="fillin" id="fillin" size="40">

</body>
</html>

Willy Duitt
12-28-2003, 09:29 AM
Yep;

This would be why double-posting (http://www.htmlforums.com/showthread.php?s=&threadid=32913) can be a problem.
Someone answers one post and then someone comes along
and answers the other. Perhaps a Mod will join the two threads
so that the responses do not get further disjointed.

.....Willy

agent002
12-28-2003, 09:51 AM
How is this double posting possible? You can't post two times within 60 seconds. I have accidently posted the same reply 5 times, though... :P