Solved

HTML radio input onclick problem

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

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…

728 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