Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Jquery onclick

Posted on 2012-12-24
9
Medium Priority
?
874 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
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 38

Accepted Solution

by:
Tom Beck earned 1600 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 400 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
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)
Suggested Courses

885 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