Select Option from another forms radio button

Robert Granlund
Robert Granlund used Ask the Experts™
I have two forms on a page.  One form has radio buttons.  All of the values of the radio buttons are equal to the values of Select Options on another form.  If a user clicks on one of the radio buttons on form 1  I want to automatically change the selected on form two to the that value of the radio button.

var sensorpick is from the raio button and $sensors is the ID of the Select on the second form:
$("#sensor-choose").change(function() {
	var sensorpick = $("input:radio[name='sensor-choose']:checked").val();
	$('#sensor option[value="' + sensorpick+ + '"]').prop('selected', true);

<form method="GET" id="sensor_finder">	
		if you already have a Coherent sensor or meter, please make your selection below.<br />
	<!--  START Find a Sensor  -->	
		<div class="form-control">
			<select name="sensor" id="sensors">
				<option value="">Find a Sensor</option>
				{exp:channel:entries channel="measurement" dynamic="no"}
					{if sensor_or_meter == "Sensor"}
						<option value="{measurement_product_name}">{measurement_product_name}</option>

Open in new window

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
You are using id for multiple radios?
Most Valuable Expert 2017
Distinguished Expert 2018
As sajayj2009 pointed out you are using the id of the radio instead of the name

Secondly, to set the selected option of a drop down you just have to set the value of the select.

Third - a radio button is easy - when you click it it is set - so all you have to do is pick the item that is clicked and use its value;

// Using .click() rather than .change()
$'"input[name="sensor-choose"]').click(function() {
  // $(this).val() is the value of the clicked radio - so we can use that
  // to set the select val - which will choose the correct option

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial