Solved

Jquery onclick

Posted on 2012-12-24
9
827 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
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)

762 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

19 Experts available now in Live!

Get 1:1 Help Now