0

I have a webserver running, which has a page containing a table with description and checkbox. What I need is to modify the row, therefore modify the state of the checkbox.

But when I click on the row to open a window from which I can edit the values, the checkbox is always set to false, even if it was true.

Here is the piece of my code that doesn't work:

if (selected_obj){
                      var markup = [
                          '<div class="confirmOverlay" id="edit_row_overlay">',
                          '<div id="edit_row_box" class="confirmBox">',
                          '<h1>Edit Row</h1>',
                          '<fieldset class="field">',
                          ' <label for="id_name">name:</label>',
                          ' <input type="text" name="name" id="id_name" value='+selected_obj.name+'>',
                          '</fieldset>',
                          '<fieldset class="field">',
                          ' <label for="id_description">description:</label>',
                          ' <input type="text" name="description" id="id_description" value='+selected_obj.description+'>',
                          '</fieldset>',
                          '<fieldset class="field">',
                          ' <label for="jqxcheckboxvalue">value:</label>',
                          ' <input type="checkbox" name="value" id="jqxcheckboxvalue" ' +
                          'value='+($('#jqxcheckboxvalue').is(':checked'))+'>',
                          '</fieldset>',
                          '<fieldset class="field buttons">',
                          '<div id="confirmButtons">',
                          ' <button id="save_add_parameter" class="button blue">${translator("save").title()}</button>',
                          ' <button id="close_add_parameter" class="button gray">${translator("close").title()}</button>',
                          '</div>',
                          '</fieldset>',
                          '</div></div>',
                      ].join('');

How can I get the state of the checkbox? Thank you

2 Answers 2

1

You can use is() and :checked

alert($('#jqxcheckboxvalue').is(':checked'));
Sign up to request clarification or add additional context in comments.

2 Comments

I use the pop up window to edit the value, alert() doesn't allow it and even if I use is(:checked) in the value of the input it doesn't get anything
@Camilla Try var isChecked = $('#jqxcheckboxvalue').is(':checked'); alert(isChecked)
0

You can use :checked and length as follow:

if($('#jqxcheckboxvalue:checked').length > 0)

2 Comments

#jqxcheckboxvalue is unique, don't need to check length
It has checked pseudo class, so it is checking if checked + id 's length is greater than 0 or not and note the id alone

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.