/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Taking a true/false statement and making a checkbox checked

Hi guys, I’m very new with javascript and using jquery, so please help if you can. I’m going to try and explain my situation best as possible.

Basically I’m getting a value from the database either true/false. I have a alert box that shows it being true/false. I want a checkbox to be checked if true else not.

Here is the line of code that I have and it just automatically checks everytime, which I obviously don’t want. Any help would be great and I’m sure I’m just missing something very easy.

$(‘#returnableCheckbox’).attr(‘checked’, $(selectedPlatform).find (‘.equipmentReturnable’).val())

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@NewBWebDevauthorApr 14.2010 — Hey guys I figured it out, I had to take the hidden value which was a string and turn it into a boolean. Which it now looks like this for all you guys that were wondering or not.

$('#returnableCheckbox').attr('checked', $(selectedPlatform).find('.equipmentReturnable').val() == "true" ? true : false );
×

Success!

Help @NewBWebDev spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...