Welcome visitor
* Login
* Register
It is currently July 24th, 2019, 5:01 am
All times are UTC [ DST ]
* Search
View unanswered posts - View active topics

FORUMS » Client Side » JavaScript



Post new topic Reply to topic  [ 2 posts ] 
Author Message
  How to dinamically change the href attribute on links
PostPosted: October 15th, 2009, 10:15 pm 

Posts: 61
hi,

I would like to ask your help on this. I have 3 links which are related to radio buttons. Can I change the folder of the href of the links according to the selected radio?

//this is the few javascript that i have...
<script type="text/javascript">
user = new Array();
user[0]= 'mark';
user[1]= 'tom';
activeUser = 0;
</script>


<input type="radio" checked="true" onclick="redirect(this.value);" name="radio1" value="0" id="mark"/>
<label for="mark">mark</label>
<input type="radio" onclick="redirect(this.value);" name="radio1" value="1" id="tom"/>
<label for="tom">tom</label>
<br />

<a href="mark/intro.htm">intro</a><br />
<a href="mark/home.htm">home</a><br />
<a href="mark/account.htm">account</a><br />


Top
 Profile  
 
  Re: How to dinamically change the href attribute on links
PostPosted: October 16th, 2009, 3:45 am 
User avatar

Posts: 112
hth
<script type="text/javascript">
user = new Array();
user[0]= 'mark';
user[1]= 'tom';
activeUser = 0;

function redirect(userSelected){
for(i=0; i<document.getElementById('section').getElementsByTagName('a').length; i++){
s=document.getElementsByTagName('a')[i].href;
document.getElementsByTagName('a')[i].href = s.replace(user[activeUser], user[userSelected]);
}activeUser = userSelected;}
</script>

<div id="section">
<input type="radio" checked="true" onclick="redirect(this.value);" name="radio1" value="0" id="mark"/>
<label for="mark">mark</label>
<input type="radio" onclick="redirect(this.value);" name="radio1" value="1" id="tom"/>
<label for="tom">tom</label>
<br />

<a href="mark/intro.htm">intro</a><br />
<a href="mark/home.htm">home</a><br />
<a href="mark/account.htm">account</a><br />

</div>


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

FORUMS » Client Side » JavaScript


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron