Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Concat Variables to build URL 1

Status
Not open for further replies.

mcmon999

IS-IT--Management
Mar 3, 2005
21
GB
Hi,

I apologise in advance but i'm very new to this.

I'm trying to join three variables to build a URL:

<html>
<head>
<script type="text/javascript">
var a = 'var b = '%PRODUCT_FIELD(MovieURL,1)%';
var c = '&test';

function url(a, b, c)
{
url = a+b+c
return url
}

</script>
</head><body><br><br>
<a href="url()">Click Here</a>
</body>
</html>

Am i right in creating a function to do this? i don't seem to be able to call it into the href?

Where am i going wrong?

Thanks in advance!!
 
Hi

[ul]
[li]You are not passing actual parameters to your functio so remove the formal parameters.[/li]
[li]Dive different name to the function and variable.[/li]
[li]Make the request for the URL yourself, the browser will not do it automatically.[/li]
[/ul]
Code:
<html>
<head>
<script type="text/javascript">
var a = '[URL unfurl="true"]http://www.testing.com?';[/URL]
var b = '%PRODUCT_FIELD(MovieURL,1)%';
var c = '&test';

function url()
{
  [red]u[/red] = a+b+c
  return [red]u[/red]
}
</script>
</head>
<body>
<a href="[red]javascript:location.href=[/red]url()">Click Here</a>
</body>
</html>

Feherke.
 
Hi,

I have made some functions which I find usefull when doing stuff with querystring variables..

Code:
function isDefined(variable) {
  return (!(!( variable||false )))
}

function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");

  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  }
} // End of function getQueryVariable

You see, if you do a .href and you have a NULL querystring-variable, you will provoke an error..

So, I gather querystringvariables like this:

Code:
var strSort = getQueryVariable("sorting");
if (!isDefined(strSort)) {
  strSort = "";
}

What happends there, is that if the variable is not in the querystring, or its empty, JS will fill it with an empty string (""). "" is not the same as NULL/NOTHING, which will provoke an error!

So, after this "wash" is done, you can do the .href and sleep safe at night..

I took this code from a working page I have made..
My page extracts the querystringvariables which are interesting to me.. Then I modify them and send some back in the original state to the browser.

The backend code then gets new results based on the modified querystringvariables.. Works quite simple, but theres no point in making it more advanced :)

In this particluar example, I check the size of the browser, subtract the width of other content and then I calculate the "gridsize", so I can show an optimal imagesearch with columns and rows (posted via querystring .href)

Olav Alexander Mjelde
Admin & Webmaster
 
Hey, this is close to what I need. Maybe you can help?
Scenario:
Static page. HTML or PHP. Page contains an assortment of images. User can click an image to set a variable. (No problem). But user can choose only one to keep.
Now here's my problem. There are various standard static html links on the page. But one link needs the variable appended to the querystring. (Get is fine. No form.) This link loads a php page and takes action on the variable in the querystring.
My toys are CSS, HTML, ASP & PHP. Very little expierence with javascript> And ajax? A cleanser isn't it?

Thanx
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top