/    Sign up×
Community /Pin to ProfileBookmark

dynamic hyperlink

Hello,

Is it possible to make a hyperlink dynamic?

Basically, I have a problem that when my page is loaded the html tags are compiled by the browser and the link I have set to a variable is always set to the default value. I want to update the variable using javascript and allow the user to link using the same button but it will actually take them different places based on the outcome of the javascript.

I am unable to update the link using javascript. How do I create a tag that will be compiled at run time?

Thanks for the help.

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@PittimannFeb 07.2005 — Hi!

You can change the href of the anchor tag or its' event handlers depending on some js outcome. What exactly do you have in mind?

Cheers - Pit
Copy linkTweet thisAlerts:
@cberg76authorFeb 07.2005 — Hey Pittimann!

Thanks for replying. Can you explain how to update the href portion of the anchor tag at runtime?

Here is the code that I wrote that doesn't work cause the anchor never gets updated at runtime:

<html>

<head>

<script language="javascript">

var selection = "default";

function setGender(gender)

{

selection=gender;

}

</script>

<style type="text/css">

.text

{

font-family:helvetica;

font-size:12px;

font-style:normal;

text-align:center;

padding-top:20;

}

#selectlayer

{

position:absolute;

left:215px;

top:50px;

}

#buttonlayer00

{

position:absolute;

left:150px;

top:200px;

}

#buttonlayer01

{

position:absolute;

left:300px;

top:200px;

}

#instructionlayer

{

position:absolute;

left:200px;

top:150px;

}

#nextbuttonlayer

{

position:absolute;

left:235px;

top:300px;

}

</style>

</head>

<body>

<script language="javascript">

</script>
<div id="selectlayer"><img src="http://home.san.rr.com/greenrealm/default.gif"></div>
<div id="buttonlayer00"><img src="http://home.san.rr.com/greenrealm/male.gif" alt="male" onmousedown="document.images[0].src='http://home.san.rr.com/greenrealm/maleselect.gif'; setGender('male');" border="2"></div>
<div id="buttonlayer01"><img src="http://home.san.rr.com/greenrealm/female.gif" alt="female" onmousedown="document.images[0].src='http://home.san.rr.com/greenrealm/femaleselect.gif'; setGender('female');" border="2"></div>
<div id="instructionlayer" class='text'>Make a gender selection</div>
<script language="javascript">

var str;

str="<div id='nextbuttonlayer' class='text'><a href='hobby.html?gender=";

str+=selection;

str+="'>next ></a></div>";

document.write(str);

</script>

</body>

</html>


Thanks again.
Copy linkTweet thisAlerts:
@jettlarueFeb 07.2005 — im not exactly sure but here is a javascript that will make the link dynamic:[code=php]
<script>
var name=prompt("Enter name","");
var age=prompt("Enter age:","");
var loc=prompt("Enter location:,"");
if (name == "" || age == "" || loc == ""){
document.write("Please reload page and fill in all of the items");
} else {
document.write("<a href=javascript:dp='Your name is:"+name+"<br>Your age is:"+age+"<br>Your location is:"+loc+"<br>';>Click here</a>");
</script>
[/code]

it probably isnt exactly what you want but im sure you could configure it
Copy linkTweet thisAlerts:
@cberg76authorFeb 08.2005 — I figured it out by using your suggestion Pittimann. I replaced the setGender() function call with a getElementById() to retrieve the anchor and then I was able to update the href.

Thanks for the help everybody.
×

Success!

Help @cberg76 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...