Solved

Change the hyperlink when I click to the radio button

Posted on 2006-06-15
4
458 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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