Solved

Change the hyperlink when I click to the radio button

Posted on 2006-06-15
4
457 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

726 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