Hell.Bent
Hell.Bent

Reputation: 1677

jquery popup alternative to javascript window solution we are using in SharePoint

We have a customized asp.net web form page (generated by sharePoint). The page has been customized with a button that opens up a window using javascript to a second asp.net page for a search and asp.net gridview selection process. Perhaps the platform is not important, but that second page gemerates javascript on the fly to send selected information from the selected itemon the grid to first page's form form fields. That code is below and does work great.

Can somebody suggest a jquery alernative to this? Will I need a jquery addin if using jquery from Google's site.

Ideally what we want is to pop up a window that allows us to search an external datasource and then select from entries found and automatically fill sharepoint form columns. the javascript code we have does work.

<a href="javascript:PS=window.open('PS.aspx','PS','width=800,height=600,scrollbars=1');PS.focus()">
CLICK HERE TO SEARCH FOR PHYSICIAN
</a>

<script language="VB"  runat="server">

    Protected Sub PhysicianGrid_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles PhysicianGrid.SelectedIndexChanged
       'session("firstname") = PhysicianGrid.SelectedRow.Cells.Item(2).Text
       Dim strjscript as string = "<script language=""javascript"">"
       strjscript = strjscript & "passvalue('lastname','"+PhysicianGrid.SelectedRow.Cells.Item(1).Text+"');"
       strjscript = strjscript & "passvalue('firstname','"+PhysicianGrid.SelectedRow.Cells.Item(2).Text+"');"
       strjscript = strjscript & "passvalue('Phone','"+PhysicianGrid.SelectedRow.Cells.Item(8).Text+"');"
       strjscript = strjscript & "<" + "/script>"
       Literal1.text = strjscript
    End Sub
 </script>

Upvotes: 0

Views: 1399

Answers (2)

ShankarSangoli
ShankarSangoli

Reputation: 69905

You can just try to improve your code using jquery as below;

Add a class name or id to this anchor and use jquery to attach the click event handler instead of using href.

<a class="searchPhysician" href="javascript:void(0);">CLICK HERE TO SEARCH FOR PHYSICIAN</a>


$(function(){

   $("a.searchPhysician").click(function(){
      var PS = window.open('PS.aspx','PS','width=800,height=600,scrollbars=1');

      PS.focus();//Sometimes in IE this will fail so its better you delay sometime and focus the window.
      //setTimeout(function(){
      //   PS.focus();
      //}, 200);

      return false;
   });
});

Upvotes: 1

Marc B
Marc B

Reputation: 360562

window.opener is an object that points at whatever window/tab opened the current window. You shouldn't have to generate javascript on the fly to pass values back and forth. A simple

window.opener.lastname = ...
window.opener.firstname = ...

should do the trick of setting those values in the parent window, and then a function call to indicate to the parent that the data's available:

window.opener.dataIsReady();

The same goes for passing data from the parent to child windows:

w = window.open(...);
w.somevar = somevalue;
w.someFunc();

Upvotes: 1

Related Questions