No PHP? No Problem*

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

No PHP? No Problem*

Post by Gen-ik »

I don't know if this will be handy for anyone.. it's a little function I coded that allows you to send variables from page to page without any server-side code (like PHP) and without having to submit a form.

To use it simple copy and paste the following script into the <head> of your html page.

You can then send variables from page to page using the default my_page.html?username=bob&age=18 type method... then the variables will be available to JavaScript and can be used however you want.

Code: Select all

<script language="JavaScript">
var url_u = window.location.href;
if(url_u.indexOf('?')!=-1?true:false)
&#123;
var url_v = url_u.split('?')&#1111;1];

if(url_v.indexOf('&')!=-1?true:false)
&#123;
var url_l = url_v.split('&');
for(var i=0; i<url_l.length; i++)
&#123;
eval("var "+url_l&#1111;i].split('=')&#1111;0]+" = url_l&#1111;i].split('=')&#1111;1]");
&#125;
&#125;
else
&#123;
eval("var "+url_v.split('=')&#1111;0]+" = url_v.split('=')&#1111;1]");
&#125;
&#125;
</script>
Bennettman
Forum Contributor
Posts: 130
Joined: Sat Jun 15, 2002 3:58 pm

Post by Bennettman »

Thanks, that'll be quite useful for putting PHP variables into JS ^_^
derek
Forum Newbie
Posts: 17
Joined: Sat Aug 16, 2003 11:31 am

Post by derek »

Yeah I'm agree with you. nice function to use in coding.
Post Reply