1

Friends

Im writing a jsp that opens a pop-up window using jQuery that has checkboxs and a user can then select all checkbox values on a pop-up window and then on Submit , it gets displayed to the parent window, So far I am able to open up a pop-up on click that displays the list of checkboxes and Im struggling to send the checked checkbox values to the parent page , Please suggest

My code is

<form action= "" id ="overlay_form" method= "post" style="display:none">
        <h3>Select Language</h3> 
        <br /><br />
        <input type="checkbox" name="countryCheckbox[]" value="English" /> English  <br/>
        <input type="checkbox" name="countryCheckbox[]" value="French" /> French  <br/>
        <input type="checkbox" name="countryCheckbox[]" value="Norwagian" /> Norwagian  <br/>
        <input type="checkbox" name="countryCheckbox[]" value="Swedish" /> Swedish <br/>
        <input type="checkbox" name="countryCheckbox[]" value="Chinese" /> Chinese <br/>
        <br /><br />
        <div class="row-fluid grid-footer">
        <div class="span8"></div>
        <div class="span5">
        <input class="btn btn-primary btn-primary-secondary" type="submit" name="saveDepartmentBtn" id="saveOrg" value="Save" onclick="this.disabled='disabled'; document.getElementById('saveOrg').disabled='disable';this.form.submit(); ">
          </div>
          <div class="span1">
        <button  class="btn btn-secondary" type="button" cancel-action="/admin/role/list" ><spring:message code="common.cancel" /></button>
        </div>
        </div>
    </form>
<p id="text">
                Selected Languages are: 
            </p>

Now to send the checked checkboxes data to the parent my JQuery code is

$(document).ready(function(){
        $('#overlay_form').submit(function(){

                    $('input:checkbox:checked').each(function(){
                        window.parent.$("#text").text(parent.$("#text").text() + $(this).val()+" ,");

                    });
                    parent.$.close();
                    return false;
        });             
    });

However Send the selected checkboxes data to the Parent window is not working Please advice

4

1 回答 1

1

你实际上并没有创建一个真正的窗口。这是一个覆盖。所以它不是一个弹出窗口,也不是一个窗口,因此没有window.parent你正在工作的内容。

相反,您有一个隐藏的 div / 表单,它会显示并定位在您的窗口上方。由于这一切都是通过 CSS 和 Javascript 完成的,因此parent您的表单没有任何内容,因为它与您的其余标记位于同一窗口中。

我敢肯定,如果您查看浏览器的 javascript 控制台,您会看到类似window.parent is null / not an object.

这就是解释。这是答案:从您的代码中删除window.parent和。parent而且由于它不是窗口,因此您也不closing是窗口,因此您close的可能是fadeOut.

$(document).ready(function(){
    $('#overlay_form').submit(function(){

                $('input:checkbox:checked').each(function(){
                    $("#text").text($("#text").text() + $(this).val()+ " ,");

                });
                $('#overlay_form').fadeOut(500);

                return false;
    });             
});
于 2013-06-04T20:27:00.193 回答