Solved

Jquery onclick

Posted on 2012-12-24
9
832 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
javascript: add id amounts 5 47
How to show span when clicked on? 10 22
How do I pull the base url for use in html links 7 23
Jquery 2 13
What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
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.
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)
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…

809 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