Solved

Change the hyperlink when I click to the radio button

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jQuery Validate 4 36
age from date of birth 4 42
Angular service to share objects between controllers 1 15
How to make a moving character 3 57
In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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…

776 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