Note that there are some explanatory texts on larger screens.

plurals
  1. POjquery simulate click, check boxes and call function
    primarykey
    data
    text
    <p>I have set up a workspace area which represents a blank PDF page where users can select paper size using radio buttons, orientation of landscape or portrait using radio buttons and personal motivation and goal statements using checkboxes. The user checks / unchecks the statement(s) they would like to place on the workspace and are also able to drag and drop them.</p> <p>When a user changes the orientation I need all the checked statement items to be briefly saved, which I am putting into an array. Then uncheck all the checkboxes of the statements that were chosen to be added (this works) and remove all the statements from the workspace (this does not work). I need to then loop through the array to go back and check the checkboxes (this works) and call the BoardElement function (this does not work) to run the ajax call.</p> <p>The related code I am using is below, and have tried many suggestion from different posts. The OrientationChange function is what I am using to attempt the save, remove and call to BoardElement which gets the elements.</p> <p>Thanks.</p> <p>HTML </p> <pre><code> &lt;h3&gt;Paper Size&lt;/h3&gt; &lt;input type="radio" name="paper_size" id="paper_size1" value="8-5x11" checked="checked" /&gt; 8.5&amp;quot;x11&amp;quot; &amp;nbsp; &lt;input type="radio" name="paper_size" id="paper_size2" value="11x17" /&gt; 11&amp;quot;x17&amp;quot; &lt;/fieldset&gt; &lt;fieldset&gt; &lt;h3&gt;Orientation&lt;/h3&gt; &lt;input type="radio" name="orientation" id="orientation1" value="l" checked="checked" /&gt; Landscape &amp;nbsp; &lt;input type="radio" name="orientation" id="orientation2" value="p" /&gt; Portrait &lt;/fieldset&gt; &lt;fieldset&gt; &lt;h3&gt;Elements&lt;/h3&gt; &lt;input type="checkbox" name="board_element_cb" id="board_ele_0" value="0" /&gt; "Who Am I" Image&amp;nbsp; &lt;input type="checkbox" name="board_element_cb" id="board_ele_1" value="1" /&gt; "Who Am I" Text&amp;nbsp; &lt;input type="checkbox" name="board_element_cb" id="board_ele_2" value="2" /&gt; Mission Statement&amp;nbsp; &lt;/fieldset&gt; </code></pre> <p>jQuery</p> <pre><code>$(document).ready ( function () { BoardElement = function () { var elements_array = new Array('wai_img_', 'wai_text_', 'mission_text_', 'affirmation_text_', 'gratitude_text_', 'role_model_'); if ($(this).is(':checked')) { var data_string = 'board_element=' + $(this).val(); $.ajax ({ type: 'POST', url: 'get_board_element_ajax.php', data: data_string, success: function(html) { $('#board_area').append(html); $('.draggable_item').draggable ({ containment: '#board_area', stack: '#board_area div' }); } }); } else { var checked_value = $(this).val(); $('.draggable_item').each ( function () { if (this.id.indexOf(elements_array[checked_value]) &gt; -1) { $('#' + this.id).remove(); } }); } } $('input[id^=board_ele_]').click(BoardElement); // save, remove and get selected board items on orientation change OrientationChange = function () { var board_ele_array = new Array(); // save $('input[id^=board_ele_]').each ( function (i) { if ($('#board_ele_' + i).is(':checked')) { $('#board_ele_' + i).attr('checked', false); board_ele_array.push(i); $('#board_ele_' + i).attr('checked', false); } }); //for (var j = 0; j &lt; board_ele_array.length; j++) //{ var j = 0; function BoardEleCheckbox () { if (j &lt; board_ele_array.length) { $('#board_ele_' + board_ele_array[j]).attr('checked', true); //$('#board_ele_' + board_ele_array[j]).click(); //BoardElement(); $('#board_ele_' + board_ele_array[j]).click(BoardElement); j++; setTimeout(BoardEleCheckbox, 1000); } } setTimeout(BoardEleCheckbox, 1000); //} } $('input[name=orientation]').click(OrientationChange); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload