473,396 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

select from list in pop-up window and set value of text box in parent window

How to's:

I have java script that opens a new window now inside my pop-up window I have list of names display and I want to select the names and insert it on my PHP page text box. Anybody who can show me how to do this?

thanks!

Expand|Select|Wrap|Line Numbers
  1. echo '
  2.     <h2>' . ( $id ? translate ( 'Edit Entry' ) : translate ( 'Add Entry' ) )
  3.  . $eType_label . '&nbsp;<img src="images/help.gif" alt="' . translate ( 'Help' )
  4.  . '" class="help" onclick="window.open( \'search_contact.php'
  5.  . ( empty ( $id ) ? '?add=1' : '' )
  6.  . '\', \'cal_help\', \'dependent,menubar,scrollbars,height=400,width=800,'
  7.  . 'innerHeight=420,outerWidth=420\' );" /></h2>'
  8.  
Apr 6 '09 #1
20 7250
JosAH
11,448 Expert 8TB
There no Java in your question; where do you want me to move your question to? A Javascript forum or a PHP forum?

kind regards,

Jos (moderator)
Apr 6 '09 #2
Hi Josah,

Originally I posted this thread on PHP but I was told by Markus to put this on JAVA forum.

Basically after doing the pop-up window I just wanted to grab the variable selected to the other page. I hope I discribe the process I wanted to do well. Now Im looking for answer how to do this.

thanks again
Apr 6 '09 #3
I have java script inside my php that opens a 2nd page window. What I wanted to do is to select the name (for example) from the pop-up window and send the value to my original page on PHP text box. Anybody who can show me how to do this?


Expand|Select|Wrap|Line Numbers
  1. echo '  
  2.     <h2>' . ( $id ? translate ( 'Edit Entry' ) : translate ( 'Add Entry' ) )  
  3.  . $eType_label . '&nbsp;<img src="images/help.gif" alt="' . translate ( 'Help' )  
  4.  . '" class="help" onclick="window.open( \'search_contact.php'  
  5.  . ( empty ( $id ) ? '?add=1' : '' )  
  6.  . '\', \'cal_help\', \'dependent,menubar,scrollbars,height=400,width=800,'  
  7.  . 'innerHeight=420,outerWidth=420\' );" /></h2>'  
  8.  
  9.  
  10.  
  11.  
Apr 7 '09 #4
dmjpro
2,476 2GB
You want to send back the name from pop-up window to opener window.
You should have a event handler on the pop-up window when you will send back the name to opener window. Access your opener document using "opener.document" in pop-up window JavaScript ;)
That's what you wanted ?
Apr 7 '09 #5
JosAH
11,448 Expert 8TB
@mychikka
Hi,

it definitely isn't a Java question; there's a bit of Javascript in your file but you also mention PHP (on the server side?) It was a mistake to redirect you to this Java forum (there is no Java in the vicinity ;-)

I'll move it to the Javscript forum; good luck.

kind regards,

Jos
Apr 7 '09 #6
acoder
16,027 Expert Mod 8TB
Once you have access to the opener window, to set the text box value:
Expand|Select|Wrap|Line Numbers
  1. opener.document.getElementById("textboxID").value = val;
where "textboxID" is the ID of the text box and val is the value selected.
Apr 7 '09 #7
Here's what I got after encorporating acecoder's code but it doesn't do anything. By the way I put this script on the pop-up window or second window. Please let me know what im missing.

Expand|Select|Wrap|Line Numbers
  1. echo "<input type='button' value='Select' onclick=window.opener.document.getElementById( 'ContactID' ).value = value_from_contactbox  window.close()'>"; 
  2.  
Apr 8 '09 #8
or should I add any on the main page where it's calling the pop-up window?
Apr 8 '09 #9
acoder
16,027 Expert Mod 8TB
Two things:
1. is value_from_contactbox set correctly by the time you click on the button?
2. You need a semi-colon after that statement before window.close().
Apr 9 '09 #10
Hi acoder, the variable im picking is a result of my query that is displayed in a list and I have a select button (below) to catch the value of the row (which is the contactid)
but still not working (sigh*) I hope im almost there.

Expand|Select|Wrap|Line Numbers
  1. echo "<input type='button' value='Select' onclick='window.opener.document.getElementById( 'Contact' ).value = '". $row['contactid']."' ";
Apr 9 '09 #11
Frinavale
9,735 Expert Mod 8TB
Sorry to bud in here but I remember something about having to set the name of the parent window for the opener to work....experts if I'm wrong here please correct me :)

Did you set the name of the Parent window before opening the Child window (popup window)?

For example:
Expand|Select|Wrap|Line Numbers
  1. <body onload="window.name='ParentWindowName'">

Aside from that, I would recommend that you put your JavaScript in a method instead of directly in the button click event. This is simply easier to read especially if you have "if" statements....for example....Oh! wait a sec...By rewriting your JavaScript into a function I found your problem.

You're attempting to access a variable that exists on the server in your JavaScript code. You cannot access $row['contactid'] in your JavaScript method because this variable exists on the server.

Well, actually this might not be your problem if your list submits the page to the PHP code when the users selects something...then your button would have had the correct values. Regardless, I believe that you have looked over this fact. (Maybe, I should just stick with .NET :) )

Try retrieving the selected value using JavaScript in order to set the text box in your parent page.


For example (the following assumes that you're attempting to print an item selected in a <select> list with the ID = "idOfList"):
Expand|Select|Wrap|Line Numbers
  1. echo "<script type='text/javascript'>"
  2. echo " function setTextBoxValue(){"
  3. echo "   if (window.opener && !window.opener.closed) {"
  4. echo "     var dropDownList = document.getElementById('idOfList');"
  5. echo "     var selectedIndex = dropDownList.selectedIndex;"
  6. echo "     var selectedValue = dropDownList[dropdownIndex].value;"
  7. echo "     window.opener.document.getElementById('Contact').value = selectedValue ;" 
  8. echo "   }"
  9. echo "}"
  10. echo "</script>
  11. echo "<input type='button' value='Select' onclick='setTextBoxValue();' />"
  12.  



-Frinny
Apr 9 '09 #12
a little progress here... my java is functioning except it didn't catch the value

My Java on to of the <body> tag

Expand|Select|Wrap|Line Numbers
  1. <script language="javascript"> 
  2. function contactid(contactid) 
  3. window.opener.document.getElementById( 'Contactid' ).value =textcontactid; 
  4. window.close(); 
  5. </script> 
MY PHP CODE -- I put the value to pick on the text box
Expand|Select|Wrap|Line Numbers
  1. echo "<td><input type='text' name=\"textcontactid\" value='". $row['contactid']. "'>";
  2. echo "<input type='button' value='". $row['contactid']. "' onclick=\"contactid()\" >";

RESULT:

[object] --- SHOWS ON MY PARENT WINDOW TEXT BOX

please help :(
Apr 9 '09 #13
and my parent input box looks like this....

Expand|Select|Wrap|Line Numbers
  1. echo "<td width='100%'>
  2.     <input type=\"text\" name=\"contactid\" onclick=\"window.open('contact_search_sub.php')\"></input>"; 
Apr 9 '09 #14
acoder
16,027 Expert Mod 8TB
A few things:
1.. Watch out for the case. "contactid" and "Contactid" are NOT the same.
2. The number of parameters has to be correct.
3. In your function, you have textcontactid, but you've not set it anywhere. I would suggest passing the value in the function, e.g. when calling the function, you could use "contactid(this.form.textcontactid.value)"
Apr 10 '09 #15
3. In your function, you have textcontactid, but you've not set it anywhere. I would suggest passing the value in the function, e.g. when calling the function, you could use "contactid(this.form.textcontactid.value)"

Hi Acoder... how can i set a parameter if the value is from a query result.
eg.
". $row['contactid']. "

thank you
Apr 10 '09 #16
acoder
16,027 Expert Mod 8TB
But then this could be changed by the user (since it's a text box). For example, if you had "test" in the text box as returned by the query and then the user modified it to be "test1", the value that the text box in the parent page should be set to is "test1". In other words, use the value at the time the user presses the button, not the value when the page loaded.
Apr 10 '09 #17
Hi Acoder...

let set I assigned the query result on a textbox or i make it type= 'hidden'
Expand|Select|Wrap|Line Numbers
  1. echo "<td><input type='text' name=\"txtcontactid\" value='". $row['contactid']. "'>"; 
can i call it on my function?
Expand|Select|Wrap|Line Numbers
  1. echo "<input type='button' value='select' onclick=\"contactid($txtcontactid)\" >";
how can i assignedt he txtcontactid from the input box to a var?
Apr 10 '09 #18
acoder
16,027 Expert Mod 8TB
Yes, a bit of PHP:
Expand|Select|Wrap|Line Numbers
  1. echo "<input type='button' value='select' onclick=\"contactid('". $row['contactid']. "')\" >";
as you used to display the value in the text box.

If the value doesn't change, you don't need a text box.
Apr 10 '09 #19
acoder...

did i get it correctly? im having page error ont he pop-up window now. Below are the codes page by page.

parent window
Expand|Select|Wrap|Line Numbers
  1. <input type=\"text\" name=\"contact\"  value=\"$contact\" onclick=\"window.open('contact_search_sub.php')\"></input>";  
pop-up window java
Expand|Select|Wrap|Line Numbers
  1. <script language="javascript">  
  2. function contactid(contactid)  
  3. {  
  4. window.opener.document.getElementById( 'contactid' ).value =contact;  
  5. window.close();  
  6. }  
  7. </script>  
  8.  
pop-up window select button
Expand|Select|Wrap|Line Numbers
  1.     echo "<td><input type='button' value='select' onclick=\"contactid('". $row['contactid']. "')\" >"; 
what am i missing here? sigh*
Apr 10 '09 #20
acoder
16,027 Expert Mod 8TB
Do you have an element on the parent page with ID "contactid"?

The line:
Expand|Select|Wrap|Line Numbers
  1. window.opener.document.getElementById( 'contactid' ).value =contact; 
should be
Expand|Select|Wrap|Line Numbers
  1. window.opener.document.getElementById( 'contactid' ).value =contactid;
because contact won't be defined. contactid is the parameter passed to the function which will be defined.
Apr 13 '09 #21

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Raymond Hettinger | last post by:
Found in a pamphlet at a pre-school: --------------------------------------- Reading improves vocabulary Reading raises cultural literacy through shared knowledge Reading develops writing skills...
34
by: jblazi | last post by:
Let us assume I have a list like and would like to transoform it into the string '{1,2},{7,8},{12,13}' Which is the simplest way of achiebing this? (The list is in fact much longer and...
4
by: Roy Smith | last post by:
In the recent "transforming a list into a string" thread, we've been discussing the fact that list.pop() is O(1), but list.pop(0) is O(n). I decided to do a little timing experiment. To be sure,...
21
by: M. Clift | last post by:
Hi All, Could someone help me out with this? items = ('a', 'b', 'c', 'd') items + 1 = ( 'b', 'c', 'd', 'a') items + 2 = ( 'c', 'd', 'a', 'b') items + 3 = ( 'd', 'a', 'b', 'c') trans = 1
10
by: bearophile | last post by:
This is my first Python program (it's an improvement of a recursive version by Luther Blissett). Given a list like this: , ]]] It produces the "flatted" version: I think this operation is...
3
by: AMRaymo | last post by:
Can someone guide me in the right direction on how to enqueue and dequeue/pop and push within a linked list? I've figured out the basic idea, but getting the other options in it seems ot be a...
5
by: metaperl.etc | last post by:
The following program does not work if you uncomment #lis = + list(args) Evidently Python is opting for the nullary constructor list() as opposed to the other one which takes a sequence....
5
by: Daniel Nogradi | last post by:
The etree.Element (or ElementTree.Element) supports a number of list-like methods: append, insert, remove. Any special reason why it doesn't support pop and extend (and maybe count)?
37
by: bahoo | last post by:
Hi, I have a list like and as output I want If I myList.remove('0024') then only the first instance of '0024' is removed.
1
by: Mikle | last post by:
I need to update values in a table (where they are null or zero) with values from another table for the corresponding PopulationMemberID. Now I now that you can't update where there is a join.....
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.