PDA

View Full Version : pass value


vdmullen
09-10-2001, 06:54 PM
Problem ....,
when having, let's say, 5 buttons on page1, no matter what button is clicked, they all should open the same "next html-file".
The problem?
Each of them should pass a (different) value to the second page on which (how ??) i can use it as a hidden field in a mailform.
example:

button 1 passes value "article1"
button 2 passes value "article2"
to a page where the visitor fills out a mail-form
with the value passed from page 1.

Sorry for the poor english, but i bet my english is better than "your dutch" :-)

Thanks for the help, i've got no idea how to ...

Dr. Web
09-10-2001, 07:07 PM
<a href="next-page.html?name=joe">go</a>
<a href="next-page.html?name=mike">go</a>
<a href="next-page.html?name=jill">go</a>

Jon Hanlon
09-10-2001, 07:56 PM
Do as Dr. Web suggested, then in the second page you need:

[code]
<script language="JavaScript">

function plusUnescape(str) { // the unescape function won't convert plus signs
str = '' + str; // to spaces; like you see in search strings
while (true) {
var i = str.indexOf('+');
if (i == -1) break;
str = str.substring(0,i) + ' ' + str.substring(i+1,str.length);
}
return unescape(str);
}

function getArgument(theKey) {
var args = new Array();
var argstring = window.location.search;
if (argstring.charAt(0) != '?') return false;
argstring = argstring.substring(1, argstring.length);
var argarray = argstring.split('&');
for (var i=0; i < argarray.length; i++) {
var singlearg = argarray[i].split('=');
if (singlearg.length != 2) continue; // not a valid argument
var argsKey = plusUnescape(singlearg[0]);
var argsValue = plusUnescape(singlearg[1]);
args [argsKey] = argsValue;
}
return args[('' + theKey)]
}
function setValue() {
document.forms.secretForm.passed.value = getArgument('name');
}
</script>

<form name='secretForm' onsubmit='setValue()'>
<input type='hidden' name='passed' value=''>
</form>

[code]

This works by appending your variables to the search property of the URL - like you see in search engines:
www.someSite.com/myPage.html?name=Arie&age=27