www.webdeveloper.com
Results 1 to 5 of 5

Thread: Hyperlink to replace text

  1. #1
    Join Date
    Oct 2012
    Posts
    3

    Hyperlink to replace text

    Hello All,

    I have some anchor tags in my webpage like
    <a href="www.mysite.com/mylink" Id="ID">click here</a>

    I have a drop down on the webpage with values like 'yes' or 'no'

    If I select "yes" from dropdown the anchor tag should be replaced with static text like "Thank you for clicking"

    if I select "no" again text should be replace with hyperlink

    Thanks

  2. #2
    Join Date
    Nov 2010
    Posts
    1,083
    we would need to see your dropdown and links or at least for you to explain the logic of which option in the dropdown applies to which link

  3. #3
    Join Date
    Oct 2012
    Posts
    3
    I have hyperlinks on my webpage ,which contains IDs

    like <a href="#" id="1">click here</a>
    <a href="#" id="2">click here</a>
    <a href="#" id="3">click here</a>

    I have a Table in my DB

    like

    ID approve somecolumn
    ....................................

    1 Yes hello
    2 No hi
    3 Yes hello world

    Depending on IDs in the table the hyperlink will be replaced with text and vice versa

    for ex: when Table ID=hyperlink ID

    Thanks

  4. #4
    Join Date
    Oct 2012
    Posts
    3
    depends on approve column

  5. #5
    Join Date
    Nov 2010
    Posts
    1,083
    I don't know what the approve column does, but something like this?
    Code:
    <head>
    <style>
    span{
    display:none;
    }
    </style>
    </head>
    <body>
    <a href="#" class="one" id="link1">click here</a><span id="span1">thank you for clicking</span><select class="link1">
    <option>- choose one-</option>
    <option value="yes">yes</option>
    <option value="no">no</option>
    </select><br>
    <a href="#" class="two" id="link2">click here</a><span id="span2">thank you for clicking</span><select class="link2">
    <option>- choose one-</option>
    <option value="yes">yes</option>
    <option value="no">no</option>
    </select><br>
    <a href="#" class="three" id="link3">click here</a><span id="span3">thank you for clicking</span><select class="link3">
    <option>- choose one-</option>
    <option value="yes">yes</option>
    <option value="no">no</option>
    </select><br>
    <script type="text/javascript"> 
    var sels=document.getElementsByTagName("select")
    for (var i = 0; i < sels.length; i++) {
    sels[i].onchange=function (){
    if (this.value=="yes"){
    document.getElementById(this.className.replace("link","span")).style.display="inline";
    document.getElementById(this.className).style.display="none";
    } if (this.value=="no"){
    document.getElementById(this.className.replace("link","span")).style.display="none";
    document.getElementById(this.className).style.display="inline";
    		}
    	}
    }
    </script>
    </body>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles