从子项中选择父窗口选项

时间:2016-07-08 02:59:18

标签: javascript jquery html typeahead.js

我正在尝试根据弹出窗口中的文本搜索在父窗口中自动选择一个选项。使用typeahead我只能搜索文本值,而不是ID,所以我需要比较一下。

 //Parent Window
<form>
<select name="recipient_id" id="recipient_id">
    <option value="">----</option>
    ...
    ...
    ...
</select> <a href="javascript://" onClick="window.open(url,'_pop','width=500,height=400,status=0,directory=0,menubar=0,scrollbars=1'); return false;">Search By Name/Company</a>
</form>

//Search Window
<form id="form-attendee" name="form-attendee">
<input class="js-typeahead-attendee" id="js-typeahead-attendee" name="attendee" type="search" placeholder="Search" autocomplete="off">

 <button type="submit">
    <i class="typeahead__search-icon"></i>
 </button>
</form>
    <script>
    $(document).ready(function() {
               $("#form-attendee").submit(function() {
                    var recipientID = window.opener.$("#recipient_id");
                    $(recipientID).find("option[text='" + $("#js-typeahead-attendee").val() + "']").attr("selected", true);
                    self.close();
               });
           });

//Typeahead code here
    </script>

Used this as an example虽然我没有收到错误,但是父窗口没有更新。

您可以在http://chemoutsourcing.com/test.php上对此进行测试。单击此页面上的链接将弹出一个允许您在父窗口下拉列表中搜索名称。

0 个答案:

没有答案