Live Chat & Podcast at 1:00PM Eastern on Sunday!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Web Design & Development
Tag Cloud
access acer asus bios bsod computer crash desktop driver drivers error ethernet excel freeze gaming hard drive hardware hdmi internet laptop malware memory modem monitor motherboard network printer problem ram registry router security slow software sound toshiba trojan ubuntu 11.10 uninstall usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
Solved: HTML, using a javascript variable in <a href>

Reply  
Thread Tools
andynic's Avatar
Computer Specs
Member with 122 posts.
 
Join Date: May 2007
Location: Amsterdam
Experience: Beginner
20-Nov-2009, 09:26 PM #1
Solved: HTML, using a javascript variable in <a href>
I want to be able to append a paramter to a url used in a reference tag.

The following works as I wish:
<a href="abcu0026_u003du003cu003etextSlides.html?7">
but I want the "7" to be varialbe, similar to the "onClick" construct below which works:

<IMG src="http://lh5.ggpht.com/_BfSHtcWNuCI/SofG-e6YdPI/AAAAAAAAAPY/YFDaYVljoK0/P5120012.JPG"
width="150" height="200"
onclick="window.location='abcu0026_u003du003cu003etextThumbs.html?'+speedVa l"
alt="">

speedVal is a javascript global variable set to a value between 1 and 15.

When I try
<a href="abcu0026_u003du003cu003etextSlides.html?speedVal">
it presents the URL in the browser as
abcu0026_u003du003cu003etextSlides.html?speedVal

When I use
<a href="abcu0026_u003du003cu003etextSlides.html?"+speedVal>
It presents the URL in the browser as
abcu0026_u003du003cu003etextSlides.html?

Is there some syntax for the javascript variable that I can use?

Thanks for your help.
Andynic
Ent's Avatar
Ent Ent is offline Ent is a Trusted Advisor with special permissions.
Computer Specs
Trusted Advisor with 3,237 posts.
 
Join Date: Apr 2009
Location: United Kingdom
Experience: Intermediate
21-Nov-2009, 09:54 AM #2
Var Target="window.location='abcu0026_u003du003cu003etextThumbs.html?'" + speedVal;
onclick = Target;
Big-K's Avatar
Distinguished Member with 6,954 posts.
 
Join Date: Nov 2003
Location: Kansas
Experience: Advanced
21-Nov-2009, 09:23 PM #3
<a href="#" onclick="window.location='abcu0026_u003du003cu003etextThumbs.html?' + speedVal">link</a>

slightly simpler
andynic's Avatar
Computer Specs
Member with 122 posts.
 
Join Date: May 2007
Location: Amsterdam
Experience: Beginner
21-Nov-2009, 09:47 PM #4
Thanks, Ent and Big-K for the replies.
I ultimately used this syntax:
href="abcu0026_u003du003cu003etextSlides.htmll" onclick="this.href+='?'+speedVal;"
May switch over to Big-K's solution because it mirrors the syntax that I use in the <IMG> tag.
andynic's Avatar
Computer Specs
Member with 122 posts.
 
Join Date: May 2007
Location: Amsterdam
Experience: Beginner
21-Nov-2009, 09:50 PM #5
Forgot to credit the above syntax to Fang at WebDeveloper.
Reply

Tags
<a href=> tag, html, javascript

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 10:05 PM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.