Solved

Change the hyperlink when I click to the radio button

Posted on 2006-06-15
4
454 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
ID: 16909983
<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
ID: 16910895
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
ID: 16913204
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
ID: 16914050
thanks both, experts ;)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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…

863 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

22 Experts available now in Live!

Get 1:1 Help Now