Avatar of tjyoung
tjyoung
 asked on

Cant select checkbox dynamically

Hi,
I have an ajax call that returns a number of values.
With it I am assigning a value to an input text field (this works fine)
and trying to show a checkbox as 'checked'
I've tried a number of methods to try and check the checkbox dynamically but it simply isn't.
Is there something I'm missing?
using Jquery 1.9+
bootstrap 3

html segment
<div class="form-group form-group-xs">
<div class="col-md-4">
	<div class="checkbox">
	<label><input type="checkbox" value="1" class="styled" id="horsepower_check" name="specs[checks][horsepower]">Horsepower</label>
	</div>
</div>
<div class="col-md-8">
	<div class="col-md-12">
	<input type="text" class="form-control input-xs" value="" id="horsepower" name="specs[values][horsepower]">
	</div>
</div>
</div>

Open in new window


Script segment
$('#horsepower').val(data['engine']['horsepower']['!value']);
$('#horsepower_check').prop("checked", true);

Open in new window

JavaScriptBootstrapjQuery

Avatar of undefined
Last Comment
tjyoung

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Kim Walker

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Terry Woods

Kim's correct... commenting out the first jQuery operation causes it to work.

Demo:
http://jsfiddle.net/znvyfa26/2/
tjyoung

ASKER
Thanks for your input. Strangely after much suffering, its simply the 'style' being applied to the checkbox that was the issue. I removed the class and it worked right away.
The info above is still very good and helped me structure things a bit better regardless.
Many thanks.
tj
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck