...

View Full Version : put text into input box via a pop up



tsclan
12-12-2004, 05:35 AM
Ok I have an input box that requires the user to put in a name of a file.

So that the user is able to put in the name of that file easier I have made a link next to the input box saying "find file" when they click on it a new window pops up displaying all the files in a folder on my server.

So far I have manged that.
>>http://www.eugamers.com/hl2dq/hl2dqupdate.php

But now I need some way of the user selecting a file name from that list in the new window and then that file name then gets inserted into the input box on the original page.
Note that there are a list of file names needing to be entered so I want to make sure it goes into the input box that the user wants it to. That would most likley be the one that was clicked next to the "find file" link.

Would anyone be able to give some help on this.

As always thank you for your time.

Willy Duitt
12-12-2004, 07:24 AM
This should work in the popup:



<a href="javascript:opener.parentNode.getElementsByTagName('input')[0].value='this.innerHTML'">filelist.php</a>


.....Willy

tsclan
12-12-2004, 04:53 PM
ok i put that code into the filelist.php so that all the links have that in them but when i click on them it comes up with an error saying
"opener.parentNode is null or not an object"
Would you bea able to help on that
Thanks

Willy Duitt
12-12-2004, 05:43 PM
You will probably need to use a function on the parent page to capture and register which element was clicked on and then reference that function in the popup...

tsclan
12-12-2004, 05:48 PM
yeah i have seen it done before with like smilies like in a shout box you click on a link and a popup comes up with a list of smilies and then u click on one and it goes into the input box.
I have no idea how that is done, the only thing i know is onFocus is usally used for these kind of things but I have no idea how to use it in this situation

Willy Duitt
12-12-2004, 06:08 PM
No, what you are thinking about targets one particular form element on the opener page... What you are trying to do is target various form elements depending upon which anchor was clicked...

I thought walking back up the DOM would work by referencing the anchors parentNode (TD) and back down children of the parentNode to the first input of the parentNode... But, obviously from another window it is not registering which anchor was clicked on...

So you have two choices, write a function which will capture, register and store which anchor was clicked on so you can use it from the popup or explicitly define which form element to pass the value from the popup too...

.....Willy

tsclan
12-13-2004, 04:05 AM
I have decicded for the first choice where I need:


a function which will capture, register and store which anchor was clicked on so you can use it from the popup


But so far I have been unable to understand how to do such a thing
so far I have this
Main Page:



""I cant seem to put in the html for the input boxes in, everytime i try and
submit with them in an error comes up in the forums saying 'You have
included too many images in your signature or in your previous post'
basically the from name is stockForm and the input boxes are called stockBox, stockBox2, stockBox3. ""

<SCRIPT LANGUAGE="JavaScript">
function openpopup(popurl){
sList=window.open(popurl, "list", "width=150,height=210");
}

function remLink() {
if (window.sList && window.sList.open && !window.sList.closed)
window.sList.opener = null;
}

// -->
</SCRIPT>


Pop UP:


<HTML>
<HEAD>
<TITLE>Stock List</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--

function pick(symbol) {
if (window.opener && !window.opener.closed)
window.opener.document.stockForm.stockBox.value = symbol;
window.close();
}

// -->
</SCRIPT>
</HEAD>
<BODY>
<TABLE BORDER="1" CELLSPACING="0" CELLPADDING="5">
<TR BGCOLOR="#cccccc"><TD><B>main</B></TD><TD><B>other</B></TD></TR>
<TR><TD><A HREF="javascript:pick('AOL.psp')">AOL.psp</A></TD>
<TD><A HREF="javascript:pick('CSCO.txt')">CSCO.txt</A></TD></TR>
<TR><TD><A HREF="javascript:pick('CPQ.txt')">CPQ.txt</A></TD>
<TD><A HREF="javascript:pick('INTC.txt')">INT.txtC</A></TD></TR>
<TR><TD><A HREF="javascript:pick('NOK.txt')">NOK.txt</A></TD>
<TD><A HREF="javascript:pick('SUNW.txt')">SUNW.txt</A></TD></TR>
<TR><TD><A HREF="javascript:pick('LU.txt')">LU.txt</A></TD>
<TD><A HREF="javascript:pick('AMZN.txt')">AMZN.txt</A></TD></TR>
<TR><TD><A HREF="javascript:pick('T.txt')">T.txt</A></TD>
<TD><A HREF="javascript:pick('MSFT.txt')">MSFT.txt</A></TD></TR>
</TABLE>
</BODY>
</HTML>


From that I think its the Pick function which needs the variable from the main page as the stockBox needs to change according to what link was pressed

So basically how can I transfer a variable from the link to the pop up window so that stockBox becomes stockBoxn

Thanks

Willy Duitt
12-14-2004, 01:35 AM
http://www.webdeveloper.com/forum/showthread.php?s=&threadid=51362



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum