Solved

Jquery onclick

Posted on 2012-12-24
9
829 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
 
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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
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…

914 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

17 Experts available now in Live!

Get 1:1 Help Now