Solved

Change the hyperlink when I click to the radio button

Posted on 2006-06-15
4
453 Views
Last Modified: 2012-06-21
I have a radio button
<input type="radio" name="select_export" value="export">

and a hyperlink on my html page
<a href = "index.php"><img src="export.gif" /></a>

When I click into the radio button, I want my hyperlink to be changed to <a href = "index2.php">

How I'm gonna do that?
Thanks alot
0
Comment
Question by:huy302
4 Comments
 
LVL 23

Accepted Solution

by:
basicinstinct earned 100 total points
Comment Utility
<head>
      <script language="javascript">
            function changehref(id)
            {
                  var anchor = document.getElementById(id);
                  anchor.href = 'index2.php';
            }
      </script>
</head>


<input type="radio" name="select_export" value="export" onclick="changehref('whatever');">

<a href="index.php" id="whatever"><img src="export.gif" /></a>
0
 
LVL 63

Expert Comment

by:Zvonko
Comment Utility
Single radio buttons do not make much sense. Do you mean a checkbox?
0
 
LVL 10

Assisted Solution

by:js_vaughan
js_vaughan earned 25 total points
Comment Utility
I agree with Zvonko, for situations where you only have one radio button, it's best to use a checkbox.  I used some of basicinstinct's code and modified for using a checkbox.  Take note of the body's "onload"; this was added so that if a user clicks on the link, then presses their browsers back button, it will ensure the link stays at index2.php if it was checked.

<html>
<head>
<title>Experts Exchange</title>

<script language="javascript">
<!--
 
function changehref(id)
{
    var cb = document.myForm.select_export.checked;
    var anchor = document.getElementById(id);
   
    if (cb) {
        anchor.href = 'index2.php';
    } else {
        anchor.href = 'index.php';
    }
}
 
-->
</script>

</head>

<body onLoad="changehref('whatever')">

<form name="myForm">

    <input type="checkbox" name="select_export" value="export" onclick="changehref('whatever');"> Check me for index2.php
    <br><br>
    <a href="index.php" id="whatever"><img src="export.gif" /></a>

</form>

</body>
</html>
0
 

Author Comment

by:huy302
Comment Utility
thanks both, experts ;)
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
jquery light box autoplay video getuikit 5 45
Condidional <a href = ....> 1 23
Hovering effect 9 28
Phone Dialer 5 36
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now