Solved

HTML radio input onclick problem

Posted on 2009-04-05
4
1,225 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

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.
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
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)

786 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