Solved

HTML radio input onclick problem

Posted on 2009-04-05
4
1,223 Views
Last Modified: 2012-05-06
I have an html page with two radio buttons.  When the user clicks the radio button, it should trigger the url.

The following has the correct url, but does not go to that page.  What am I doing wrong?


        <td><input onclick="/myPage?key={{myData.key|stringformat:"s"|urlencode}}" type="radio" value="foo" name="s">1</td>


0
Comment
Question by:tmonteit
  • 3
4 Comments
 
LVL 13

Expert Comment

by:numberkruncher
ID: 24071961
When using JavaScript to change location you have to either open in a new window, or adjust the windows current location.

Try the following:
<td><input onclick="window.location.href='/myPage?key={{myData.key|stringformat:"s"|urlencode}}'" type="radio" value="foo" name="s">1</td>

Open in new window

0
 
LVL 13

Expert Comment

by:numberkruncher
ID: 24071968
Also, I have just noticed that you have nested literals. Those need to be escaped.
<td><input onclick="window.location.href='/myPage?key={{myData.key|stringformat:\"s\"|urlencode}}'" type="radio" value="foo" name="s">1</td>

Open in new window

0
 

Author Comment

by:tmonteit
ID: 24071974
Can you post an example?  Thanks...

0
 
LVL 13

Accepted Solution

by:
numberkruncher earned 500 total points
ID: 24071987
It should just be a case of replacing your original code with that suggested above.

Are you using PHP? If so then use code from my first response. If you actually intend "{{myData.key ..." to appear within the link then use the code from my second response.

See an additional simplified example below:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<html>

	<head>

		<title>Demo Page</title>

	</head>

	<body>

		<h1>Demo Page</h1>

		<div>

			<input onclick="window.location.href='http://www.google.com'" type="radio" value="foo 1" name="s">

			<input onclick="window.location.href='http://www.google.com'" type="radio" value="foo 2" name="s">

		</div>

	</body>

</html>

Open in new window

0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Help with HTML 7 39
HTML Lists 3 29
Link SQL table to Webpage 9 39
Jump to a specific point on a responsive page 5 13
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

760 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

20 Experts available now in Live!

Get 1:1 Help Now