javascript querystring

This is a discussion on javascript querystring within the PHP Language forums, part of the PHP Programming Forums category; Hi guys, I have this html file containing: <html><head> <script src="variable.js?...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-21-2006
radiox
 
Posts: n/a
Default javascript querystring

Hi guys,

I have this html file containing:

<html><head>
<script src="variable.js?id=1004"></script>
</head><body></body></html>

I also have the .js file that looks like this
----------------------------------------------------------------------------------------
var id = getQueryVariable("id");
function getQueryVariable(variable)
{
var query = window.location.search.substring(1);
var vars = query.split("&");
var returned = 0;
for (var i=0;i<vars.length;i++)
{
var pair = vars[i].split("=");
if (pair[0] == variable)
{
returned = pair[1];
}

}
return returned;
}
document.write(id);
-----------------------------------------------------------------------------------------

I do a mistake somewhere and I don't get back the value of the id in
the querystring.
I get the value displayed only if i add the querystring at the end of
the html file name in the browser's address line.

It might be a small problem, but I know very little JavaScript so I
require your help.

Thanks in advance

Reply With Quote
  #2 (permalink)  
Old 04-21-2006
radiox
 
Posts: n/a
Default Re: javascript querystring

After reading more posts I have the solution.

Maybe will be of use to some

HTML FILE contains
------------------------------------------
<script type="text/javascript">
var id = "1004";
</script>
<script type="text/javascript" src="myletter.js"> </script>
-------------------------------------------------------------------------------

JAVASCRIPT FILE contains
------------------------------------------------
var id = (id);
document.write(id);
------------------------------------------------

More simple than I thought.

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 12:08 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0