PDA

View Full Version : vars in address


rbmyr81
12-27-2003, 11:19 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

Willy Duitt
12-27-2003, 11:55 PM
Here's one way:
<script type="text/javascript">
<!--//
function newThread(){
var str = 'http://www.htmlforums.com/newthread.php?s=&action=newthread&forumid=6';
str = str.split('&');
str = str[1].split('=');
str = str[1];
document.forms[0].txtbx.value=str;
}
//-->
</script>
</HEAD>

<BODY onload="newThread()">
<form>
<input type="text" name="txtbx">
</form>

....Willy

Willy Duitt
12-28-2003, 12:12 AM
FWIW: If, as in your example new thread
would always be a number. RegEx would be easier...
<script type="text/javascript">
<!--//
function newThread(){
var str = 'http://www.htmlforums.com/newthread.php?s=&action=12262003&forumid=6';
if (/action=(\d*)/.test(str)){
document.forms[0].txtbx.value = RegExp.$1*1;
}
}
//-->
</script>
</HEAD>

<BODY onload="newThread()">
<form>
<input type="text" name="txtbx">
</form>

.....Willy

rbmyr81
01-05-2004, 04:17 PM
hey... thats a bit too advanced 4 me.. could u explain it a lil more? also i'm lookin for a way to sorta carry vars so like the first page would say whats ur fav color then it would go like

var col=document.all.txtbox.value
window.location.href="www.wherever.com/whatever.html?color="+col

then i need a way to get that var in the next page, not just like a set string that it splits after the question mark.. hope u understand i dont know how to xplain it more than that lol
thx

Bobby

Willy Duitt
01-05-2004, 04:43 PM
Can you please format your question in english, using
capatalization and punctuation. I can not understand
^^ that ^^ jibberish.

Some example code reflecting what you are trying to do
would also be helpful. The best I can figure is you
wish to pass a value but what do you want to do
with it once passed needs further explanation.

.....Willy

Willy Duitt
01-05-2004, 05:23 PM
Maybe you can find your answer in this thread (http://www.webxpertz.net/forums/showthread.php3?s=&threadid=26736).

.....Willy

rbmyr81
01-06-2004, 10:29 PM
Hey sorry i didn't really know how to explain it but i think that thread helped- I really don't care if it's in the address line or not. Thanks for the help!

Bobby

rbmyr81
01-06-2004, 10:53 PM
well.. it sorta helped.. i'm just gonna give you my code and maybe it's not too far off(as you can tell, i'm quite a newbie)

<html>
<head>
<script>
function gatherData(f){
for(i=0; i<f.length; i++)
if(f[i].type == 'text')
name+=f[i].name+"='"+f[i].value+"';"
}
</script>
</head>
<body>
<form name="vars" method="post" action="get.html" onsubmit="gatherData(this)">
<input value="lol" name="bgcolor">
<input type=submit value="Go!">
</body>
</html>


here's get.html:


<html>
<head>
<script>
function onload(){
var col=eval(bgcolor.value)
document.all.btn.value=col
}
</script>
</head>
<body onload=onload()>
<input type=text name="txt">
</body>
</html>

Willy Duitt
01-07-2004, 01:42 AM
It looks like your trying to define the background color of the next page. Although I am confused about the document.all.btn.value reference. In any event, below you will find an example which allows you to define the next pages background and text colors.
Post back if this is not what you want.

Page One
<html>
<head>
<title> Pass via Window Name </title>
</head>
<body>
<script type="text/javascript">
if (typeof(document.layers)!='undefined') alert("This script does not work in Netscape 4!");

function gatherData(f){
window.name="";
for(i=0; i<f.length; i++)
if(f[i].type == 'text')
window.name+=f[i].value+',';
location=f.action;
}
</script>
<form method="post" action="RecieveValues.html" onsubmit="gatherData(this);return false">
Enter a Background Color: <input name="bgColor" value=""><br />
Enter a Text Color: <input name="fgColor" value=""><br />
<input type="submit" value="Submit" />
</form>
</body>
</html>

Page Two:
RecieveValues.html
<html>
<head>
<title> Get Info From Window Name String</title>
<script type="text/javascript">
function recieveData() {
if (typeof(document.layers)=='undefined')
var vars = window.name.split(",");
document.bgColor = "'"+vars[0]+"'";
document.fgColor = "'"+vars[1]+"'";
}
onload=recieveData
</script>
</head>
<body>
Text Color Test
</body>
</html>

.....Willy

rbmyr81
01-09-2004, 04:19 PM
yep that's pretty much it(don't ask bout the btn.value thing- i dont know what i was doing) thanks a lot!!

Bobby