jQuery, radio reset to default button

Hi,

I have a "reset" div, that will reset a radio group to default when clicked.
It works great, but it also need to change the value in this image, same value as the default radio button.

The image is placed within the "sketch_yellow" class.

$('#reset_connection_view').on('click', function() {
	$('.sketch_yellow input[type=radio]').prop('checked', function () {
		return this.getAttribute('checked') == 'checked';

		/*
		maybe somehting like this...
		#imgYellow.css(transform: rotate(???deg)) = default.radio.button.value;
		
		... not valid code, but I hope one of you understand what i'm looking for :)
		*/
	});
})

Open in new window


<img id="imgYellow" style="position: absolute; z-index: 30; width: 248px; height: 248px; transform: rotate(45deg);" src="/images/sketch/endview_connectionport_std_yellow.png">

Open in new window


 radio_img_radio_reset.png
Note: I have two radio groups/name (sketch_yellow, sketch_green), but only working on the first one atm.
kgp43Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Tom BeckCommented:
Maybe I'm missing something. Why wouldn't this be all you need?
$('#reset_connection_view').on('click', function() {
	$('.sketch_yellow input[type=radio]').prop('checked', true);
	$('.sketch_yellow #imgYellow').css({'transform': 'rotate(45deg)'});
});

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Julian HansenCommented:
$('.sketch_yellow input[type=radio]').prop('checked', function () {
		return this.getAttribute('checked') == 'checked';

Open in new window

Trying to understand your thinking here
Are you wanting to set the radio to checked or flip it?
Why not just do what Tom suggests and set the prop('checked', true)

Hint: you don't want to be using getAtribute(checked) - this does not always do what you would expect - rather work exclusively of the .prop('checked')
0
kgp43Author Commented:
I used some of Tom Beck's coding/suggestion and managed to look up the rest on Google.

$('#reset_connection_view').on('click', function() {

	$('.sketch_yellow input[type=radio]').prop('checked', function () {
		return this.getAttribute('checked') == 'checked';
	});
			
	$('.sketch_yellow #imgYellow').css({'transform': 'rotate(<?php echo $conf['connection_port_bot_angle']; ?>deg)'});
	
	$('.sketch_yellow label:has(input:radio:checked)').addClass('yellow_active');
	$('.sketch_yellow label:has(input:radio:not(:checked))').removeClass('yellow_active');
	
	$("#cpsettings").slideUp();
	
})

Open in new window


This is a bit hard to explain and it's all within a login system... sorry about the confusion.

I have recorded a small video to show you how it works.
The one to the left works (after the updates above), it reset to default radio when I click the Reset button.
I have not updated the coding on the right one yet, as you can see.

https://youtu.be/H_4SmIdxrI4
0
Tom BeckCommented:
It makes more sense now. Thanks for the video. Looks like a fun project.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.