Solved

Jquery onclick

Posted on 2012-12-24
9
836 Views
Last Modified: 2012-12-27
Hello All,

I am trying to use jquery/javascript to redirect based on a radio button onclick.

The below is code that I got from another site but it's not working.
Any ideas?


<script type="Javascript">
    $('input[type=radio]').on('click', function(){

        href = $(this).val()+".html";

        $('#form1').attr("action", href)

    })

</script>
<style type="text/css">
.style1 {
				text-align: center;
}
</style>
</head>

<body>
<form method="post">
<table style="width: 20%">
				<tr>
								<td class="style1">
								
												<input name="Radio1" type="radio" />
								</td>
								<td>Uncheck All</td>
				</tr>
</table>

Open in new window


Thanks!
0
Comment
Question by:Isaac
[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
  • 2
  • 2
  • +1
9 Comments
 
LVL 38

Expert Comment

by:Tom Beck
ID: 38718468
1.) It is <script type="text/javascript">
2.) Wrap the click event in an onReady event.
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>
<script type="text/javascript">
$(document).ready(function(){
	$('input[type=radio]').on('click',function(){

        href = $(this).val()+".html";

        $('#form1').attr("action", href)

    });
});

Open in new window

0
 
LVL 30

Expert Comment

by:IanTh
ID: 38718472
0
 
LVL 5

Author Comment

by:Isaac
ID: 38718555
Ok.. I should have gone into more details.  How do I make this work in SharePoint 2007 using a Centent Editor Webpart.  Content editor web parts does not like the form tag, so I had to take it out.

IanTh,

I'm not sure how to use your code because I have about 8 other radio buttons.

Any ideas?

Thanks!
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 38

Accepted Solution

by:
Tom Beck earned 400 total points
ID: 38719102
A simple redirect from a radio button click would look like this:
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>
<script type="text/javascript">
$(document).ready(function(){
	$('input[type=radio]').on('click',function(){

        window.location = $(this).val();

    });
});

Open in new window

0
 
LVL 15

Assisted Solution

by:Insoftservice
Insoftservice earned 100 total points
ID: 38719958
Please try out this one
lovetomarry.html
0
 
LVL 15

Expert Comment

by:Insoftservice
ID: 38722929
Hi did u checked the code provided .
0
 
LVL 15

Expert Comment

by:Insoftservice
ID: 38724149
What was the issue in my code .
Please specify.
0
 
LVL 5

Author Comment

by:Isaac
ID: 38724195
There was no issue with your code but I tried tommyboy's first a week ago and it worked.  I just forgot to give him the credit.  So, I gave you a part just to be fair.
0
 
LVL 15

Expert Comment

by:Insoftservice
ID: 38724385
ok thanx . wish you all merry xmas !!
0

Featured Post

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Set a parameter in a properties file and use in html table. 14 60
close window in firefox 3 39
Ajax success not firing alert 6 45
Secure registration PHP 7 43
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
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 how to dynamically set the form action using jQuery.
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…

710 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