Forum Moderators: open

Message Too Old, No Replies

Passing variable

I want to pass a variable from URL to html...

         

docny

8:11 pm on Jun 20, 2004 (gmt 0)

10+ Year Member


I want to pass a variable from URL to html...
for example
HTML file as below
<!--#include virtual="/example.php?i=$pid&page=$page" -->

can I pass this variable from just the url for example
http://test.com/test.html?pid=23&page=1

or else how can i do that

curlykarl

8:22 pm on Jun 20, 2004 (gmt 0)

10+ Year Member



You may find this helpful :)

[macromedia.com...]

Karl

BlobFisk

8:37 pm on Jun 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi docny,

You can add a variable to the link of your href:

<a href="page.html?var=value" title="Link Title">..</a>

Then, use the code from this thread:

[webmasterworld.com...]

To stip the variable from the URL at the receiving page.

HTH

Purple Martin

12:24 am on Jun 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here is some code I wrote ages ago to do this. It will parse any search string (the bit in the URL to the right of "?") and automatically declare all search parameters as JavaScript variables with values. It handles both numeric and string variable types correctly. Just paste it in the head.

<script type="text/javascript">
if (location.search.length > 0) {
launchString = location.search.substring(1, location.search.length);
var launchStringArray = launchString.split("&");
for (var i = 0; i <= launchStringArray.length - 1; i++) {
var left = launchStringArray[i].substring(0, launchStringArray[i].indexOf("="));
var right = launchStringArray[i].substring(launchStringArray[i].indexOf("=") + 1, launchString.length);
if (isNaN(right)) {
right = '"' + right + '"';
}
eval("var " + left + " = " + right);
}
}
</script>