SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Zealot
    Join Date
    Mar 2005
    Posts
    166
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    sending info to parent page

    Hi,

    I'm facing problems while trying to send non numbers values to my parent page...don't know the reason.
    I'm sending a recordset value to a js funtion in a popup that sets a parent field value with that value..
    The db variable is settled into text type but mainly I have numbers to retrieve from the recordset research. The point is that for some reason when the value i'm looking for isn't a number I can't manage to send it to the main page via the onclick event that calls the js function...
    Any Idea?

    The code is belowworks only when I click on a number...)

    The popup page:

    function sendInfo(pat)
    {
    var stringObject = new String(pat);
    opener.forminclui.equip_pat.value = stringObject ;

    self.close();
    }

    <form name="formpopup">

    >>rspat.open ... (recordset)


    <a href="#" onClick="sendInfo(<%=cstr(rspat.Fields("patrimonio"))%>)" class="style5"> <input name="patrimonio" type="hidden" value="<%=cstr(rspat.Fields("patrimonio"))%>"><%Response.write rspat.Fields("patrimonio")%></a>

    >>do while not recordset.eof..
    </form>


    Ps. I already tried change the stringObject on js function to reffer a form input field value ( ...=document.formpopup.patrimonio.value but then on the parent field appears "undefined"...

  2. #2
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    there is a thread a couple down that answers this question.

    use window.opener.document.getElementById('equip_pat').value = stringObject;


  3. #3
    SitePoint Zealot
    Join Date
    Mar 2005
    Posts
    166
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    no luck

    thanks for the quick reply!

    No luck adding the change you advised..stills the same scenario..

    function sendInfo(pat)
    {
    var stringObject = new String(pat);
    //opener.forminclui.equip_pat.value = stringObject ;
    window.opener.document.getElementById('equip_pat').value = stringObject;

    self.close();
    }

  4. #4
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how is your new window opened?

    also, can you post the source of the pop-up with the variables from your code behind rendered?

    Just so we can see what your code looks like.

    What type of element is equip_pat?

    stick an alert above your window.opener line with

    Code:
    alert(window.opener.document.location.href);
    What do you get, if you get the parent's page location, then the window.opener link is working and it's the control your trying to access.

    Look at both the parent and child pages and make sure everything is rendered properly, so id's, types etc.


  5. #5
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe the "equip_pat" element does not have an ID.

    You can either give it an ID and use the code that Gav posted, or instead:
    Code:
    window.opener.document.forms['forminclui'].elements['equip_pat'].value = stringObject;
    PS -
    window.opener refers to the parent of a POPUP (opened originally with window.open)
    window.parent refers to the parent of a FRAME or IFRAME
    Just to make sure you weren't in a frame.

  6. #6
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how can their be an "equip_pat" element if it has no id lol

    test1.html

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <TITLE> New Document </TITLE>
    <META NAME="Generator" CONTENT="EditPlus">
    <META NAME="Author" CONTENT="">
    <META NAME="Keywords" CONTENT="">
    <META NAME="Description" CONTENT="">
    
    <script>
    
    function createPopup()
    {
    	var win = window.open('test2.html', null, 'width=200px; height=200px;');
    }
    
    </script>
    
    </HEAD>
    
    <BODY>
    
    <form>
    
    	<input type="text" id="test" />
    		
    	<br />
    	<br />
    	
    	<div id="test1">[Awaiting Value]</div>
    
    	<br />
    	<br />
    
    	<a href="javascript:void(0);" onclick="createPopup()">Click me</a>
    
    </form>
    
    </BODY>
    </HTML>

    test2.html

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <TITLE> New Document </TITLE>
    <META NAME="Generator" CONTENT="EditPlus">
    <META NAME="Author" CONTENT="">
    <META NAME="Keywords" CONTENT="">
    <META NAME="Description" CONTENT="">
    
    <script>
    
    	function transferData()
    	{
    		var data = document.getElementById('test').value;
    
    		window.opener.document.getElementById('test').value = data;
    		window.opener.document.getElementById('test1').innerHTML = data;
    	}
    
    </script>
    </HEAD>
    
    <BODY>
    
    <input type="text" id="test" />
    
    <br />
    <br />
    
    <a href="javascript:void(0);" onclick="transferData()">Transfer Data</a>
    
    </BODY>
    </HTML>
    A note, window.opener will not work when a new window is created using: <a href="newWindow.html" target="_blank">....

    (Correct me if I'm wrong)


  7. #7
    SitePoint Zealot
    Join Date
    Mar 2005
    Posts
    166
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's some further info that shows a bit more from my parent and popup pages:
    >>Here's the select input that call's the new popup window:

    <select name="equip" class="cn" onChange="checkPatrimonio(this.value);">
    <%
    Dim rsequip
    Set rsequip = Server.CreateObject("ADODB.Recordset")
    rsequip.Open "SELECT descricao FROM Equipamentos Group By descricao Order By descricao ASC", conBD


    IF isempty(descricao) then%>
    <option value="" selected>Selecione equipamento</option>
    <option value="Nenhum">Nenhum</option>
    <%
    Else
    %>
    <option value="<%=descricao%>" selected><%=descricao%></option>
    <%
    End if


    Do While Not rsequip.Eof
    %>
    <option value="<%response.Write rsequip.Fields("descricao")%>">
    <%response.Write rsequip.Fields("descricao") %>
    </option>
    <%
    rsequip.MoveNext
    Loop

    rsequip.close
    Set rsequip = Nothing
    %>
    </select>

    >>Here's the parent code to open the popup window:
    function checkPatrimonio(descricao)
    {
    var q = descricao;
    var stringObject1 = new String("Nenhum");
    var stringObject2 = new String(descricao);


    if (stringObject1.toString() == stringObject2.toString())
    document.forminclui.equip_pat.value=stringObject2;

    else
    window.open('pesquisa_PAT.asp?descricao='+q,'Pesquisa_Patrimonio','toolbar=no,menubar=no,location=no,width=390,height=220,left=0,top=0');


    }


    >>Here's the code from popup (pesquisa_PAT.asp) that show's the result of the recordset research that matches with the variable (q) passed by my parent select input handler when called ..


    function sendInfo(pat)
    {
    var stringObject = new String(pat);
    //opener.forminclui.equip_pat.value = stringObject ;
    window.opener.document.getElementById('equip_pat').value = stringObject;

    self.close();
    }

    <a href="#" onClick="sendInfo(<%=cstr(rspat.Fields("patrimonio"))%>)" class="style5"> <input name="patrimonio" type="hidden" value="<%=cstr(rspat.Fields("patrimonio"))%>"><%Response.write rspat.Fields("patrimonio")%></a>

    >>Here's the input from my parent page which I'd like to retrieve the value from popup..

    <input name="equip_pat" id="equip_pat" type="text" class="cn" style="{FONT class=cn} " value="" size=25 maxlength=20 readonly>

  8. #8
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not to sure on this whole

    Code:
    new String('value')
    business, use

    Code:
    var stringObject1 = 'Nenhum';
    Next job is to do an if statement on the window.opener

    so

    Code:
    if(window.opener)
       window.opener.document.getElementById('equip_pat').value = stringObject;
    else
       alert('somethings wrong');
    or

    put the function sendInfo into your parent's page, and remove any window.opener reference from it, and then change all your links to

    Code:
    <a href="#" onClick="window.opener.sendInfo('<%=cstr(rspat.Fields("patrimonio"))%>')" class="style5"> <input name="patrimonio" type="hidden" value="<%=cstr(rspat.Fields("patrimonio"))%>"><%Response.write rspat.Fields("patrimonio")%></a>
    Make sure that you always stick quotation marks or aprostraphies (sp) around your values.


  9. #9
    SitePoint Zealot
    Join Date
    Mar 2005
    Posts
    166
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    it works

    So I shift the line :
    <a href="#" onClick="sendInfo(<%=cstr(rspat.Fields("patrimonio"))%>)" class="style5"> <input name="patrimonio" type="hidden" value="<%=cstr(rspat.Fields("patrimonio"))%>"><%Response.write rspat.Fields("patrimonio")%></a>

    to:
    <a href="#" onClick="sendInfo('<%=cstr(rspat.Fields("patrimonio"))%>')" class="style5">
    <input name="patrimonio" type="hidden" value="'<%=cstr(rspat.Fields("patrimonio"))%>'">
    <%Response.write rspat.Fields("patrimonio")%>
    </a>

    It works, but I'm wondering what difference the '' can made from the js functions that receives the parameter??

    Thanks to all that helps me to solve it!

  10. #10
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To be brutely honest I can't answer that without getting it wrong.

    but here i try.

    I think using apostraphies (sp) tells javascript to create a new string object in memory where as without, you are passing a reference to the original object.

    Also i'd like to correct the above state to include that you only use apostraphies (sp) if you are passing an string value.



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •