set the value for a checkbox using .prop

So, I have in my script the following code to assign the value of several text boxes that is working ok.

However, when I attempt to assign the value of a checkbox, nothing seems to be set for the checkbox. I have tried using .prop and .attr, so I am thinking my entire approach is wrong.

Some help would be greatly appreciated.

Here is my unchanged code. I am trying to assign the value of the "#id_language_detail_multiple_languages":

    function setLanguageDetailsFormValues() {

    $('#id_language_detail_display_type').val('{{ language_details.language_detail_display_type }}');

    $('#id_language_detail_multiple_languages').val('{{ language_details.language_detail_multiple_languages }}');

    ....

Answers


If you want to assign the "value" of your text boxe, you will add to do something like this:

$('#YourId').attr('value', 'setYourValueHere')

If you want to have the value of your text box, just do:

var myValue = $('#YourId').attr('value')

That is the same thing for '.prop' !

If it wasn't what you wanted, be a little more specific or give us a http://jsfiddle.net/ :-)

By the way, you can also do:

if you go 1 checkbox:

$("input[type='checkbox']").val('yourValue');

Or just:

document.getElementById('yourCheckbox').value = 'YourValue';

If the value isn't set, it will return undefined, so be aware and check if it is !


Hi You can do it like following.Properties for checkboxes are different from textboxes.

$("#CheckboxID").prop("checked","True");

if you want to read the checkbox value use like following

$("#CheckboxID").prop("checked");

Thanks.


Need Your Help

Access objects in custom UITableViewCells with same tag?

ios arrays tableview nsindexpath

In my app, I use custom UITableViewCells loaded from a XIB. Each cell contains 4 objects, like a UIImageView, UILabel, UITextField, etc...

Best way to self study Compilers: Principles, Techniques & Tools

compiler-construction

I'm trying to study the book referenced in the title but am having a hard time. Can anyone suggestion some tips?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.