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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple question 1

Status
Not open for further replies.

lisalis99

Programmer
Joined
Jan 9, 2005
Messages
121
Location
US
Hi,

I have this javascript that returns what i want, now I want to use it within an a href tag, how do I call this? Does it have to be in a function and then call the function and if so, how do I make this a function? Sorry, newbie here...

Code:
<script language="javascript">
var str = "<%currentrequest%>";
var tempStr = str.substr(str.indexOf("Params=") + 13);
document.write(tempStr);
</script>
 
Code:
<script type="text/javascript">

  function foo() {
    var str = "<%currentrequest%>";
    var tempStr = str.substr(str.indexOf("Params=") + 13);
    return tempStr;
  }

</script>

OTOH, I've no idea what you mean when you say you want to use it within a href tag. It sounds like you're better off building the href using server-side code (seeing as you're already using <%currentrequest%>.

And you should probably do some study online: google for "javascript basics" and you'll come up with loads of tutorials like this.

---
Marcus
better questions get better answers - faq581-3339
accessible web design - zioncore.com
 
Ahhh... tricky... try this instead:
Code:
<a href="javascript:document.write([b]'[/b]<%currentrequest%>[b]'[/b].substr(str.indexOf([b]'[/b]Params=[b]'[/b]) + 13));">Click me</a>
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
We're using a CMS that can only work with Javascript (bummer)so we are stuck, no server-side--I'm trying to grab a URL parameter and then use that in an a href...
it's hard to explain...

I'm trying to use that function to pull the values after the word &Param=Start=13 in the URL, I need the "13" so I can put that value in the a href below:

[%<a href="<%GalleryItemLink%>,Start=value of what the function returns" ><img src="<%ImgLink%>&maxw=48&maxh=48 border="1"></a>

 
Thanks for the info, I tried that link above with the document.write and I got str is undefined... what am I missing here? Thanks for the assistance!
 
Oh never mind I got the link... but I need to use it here:

[%<a href="<%GalleryItemLink%>,Start=value of what the function returns" ><img src="<%ImgLink%>&maxw=48&maxh=48 border="1"></a>

I need to put that value, say it's 13, after Start=, see above...

Thanks
 
pleasepleaseplease use server-side code. There doesn't seem a need for generating this link client-side. It prevents search engines from indexing the link, and breaks the link for users with JavaScript disabled (about 10% of users). What server language are you using?


Code:
<a href="[gray]<%GalleryItemLink%>[/gray],Start=value of what the function returns" >
  <img src="[gray]<%ImgLink%>[/gray]&maxw=48&maxh=48 border="1">
</a>

Your code example isn't very clear: for example:
- is [blue][tt]&maxw=48&maxh=48[/tt][/blue] part of the image src? If so, you're missing a quote mark.
- what's the comma for after [gray]<%GalleryItemLink%>[/gray]: get variables are usually marked by a question mark, and seperated by ampersands: [tt]href="[gray]<%GalleryItemLink%>[/gray][red]?[/red]Start=value of what the function returns"[/tt].




If you must do it with JavaScript, you should use an onclick event to generate the link href.
Code:
  <img src="[gray]<%ImgLink%>[/gray]&maxw=48&maxh=48" border="1" [red]onclick="[blue]window.location = '[gray]<%GalleryItemLink%>[/gray],Start=' + foo();[/blue]"[/red]>

---
Marcus
better questions get better answers - faq581-3339
accessible web design - zioncore.com
 
Thanks... I got it working with your help!! Much appreciated!
Lisa
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top