SitePoint Sponsor

User Tag List

Results 1 to 11 of 11

Hybrid View

  1. #1
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need to send value from select in a pop up to parent window

    Ok, how would I send the value from a <select> box that's in a pop up opened with window.open() back to the parent window, and put it in a text field?
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  2. #2
    SitePoint Addict
    Join Date
    May 2000
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You would use the term "opener" to refer to the form field in your main window like this:
    <HTML>
    <HEAD>
    <TITLE>Drop Down Test</TITLE>
    <SCRIPT LANGUAGE="javascript">
    function LinkUp(obj)
    {
    var myval = obj[obj.selectedIndex].value;
    opener.document.form_name.field_name.value=myval
    }
    </SCRIPT>
    </HEAD>
    <BODY BGCOLOR="lightgreen">
    <FORM NAME="DropDown">
    <SELECT NAME="DDlinks" onChange="LinkUp(this)" >
    <OPTION SELECTED>Choose a Link
    <OPTION VALUE="maxtext8.htm"> Page One</OPTION>
    <OPTION VALUE="newwin.htm"> Page Two</OPTION>
    <OPTION VALUE="open.htm"> Page Three</OPTION>
    </SELECT>
    </FORM>
    </BODY>
    </HTML>

    You can also perform a function in your main window from a popup like this:
    opener.function_name()

  3. #3
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So what goes where?
    I have no idea what should be put in the pop up page, and what should be put in the main window.

    And btw, i'm using a submit button to send it, not the thing changing.
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  4. #4
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi defender1 mentor,

    see the "Add Options from Child Window" script/tutorial at my site

    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still

  5. #5
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your site doesn't work.
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  6. #6
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi defender1 mentor,

    If you are referring to my site -- a server busy error means 'busy' not 'doesn't work'. Try reloading; aol (where my site is located) seems to be having its usual 'fast, new, easier to use' conniptions.

    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still

  7. #7
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    a server busy error means 'busy' not 'doesn't work'.
    True, but a Cannont Find Server message does

    And i have no flipping idea what any of that stuff is.

    I dont' know javascript, so that doesn't help at all.
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  8. #8
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well, i've tried request's code, and i get
    Line 30
    'value' is null or not an object
    when i click submit.
    here's my code
    Code:
    <html>
    <head>
    <title>3d artisan</title>
    <meta name="description" content="3d Artisan - Your one stop source for everything 3d.">
    <meta name="keyword" content="3d art, 3d, art, artisan, 3dartisan, art tutorials, tutorials, 3d stuio max, max, maya, lightwave, lightwave tutorials, maya tutorials, art forums, forums">
     <map name="FPMap0"> 
      <area href="/index.php" shape="rect" coords="415, 85, 445, 97">
      <area href="/resources" shape="rect" coords="452, 85, 505, 97">
      <area href="/index.php?page=hosting" shape="rect" coords="511, 85, 551, 97">
      <area href="/links" shape="rect" coords="561, 85, 589, 97">
      <area href="/gallery_index.php" shape="rect" coords="597, 85, 643, 97">
      <area href="/index.php?page=awards" shape="rect" coords="652, 85, 690, 97">
      <area href="/forums" shape="rect" coords="701, 85, 743, 97">
      <area shape="rect" coords="750, 84, 795, 97" href="/index.php?page=site_map">
      <area href="http://www.3dartisan.net" shape="rect" coords="1, 60, 163, 99">
     </map>
    <style>
    A:hover {color: #99B1CA}
    input {background: 333333; border-color: ffffff; font-family: "Verdana", "Arial", "Helvetica", "sans-serif"; color: ffffff; border-width: 1; border-height: 1; border-style: solid;}
    textarea {background: 333333; border-color: ffffff; font-family: "Verdana", "Arial", "Helvetica", "sans-serif"; color: ffffff; border-width: 1; border-height: 1; border-style: solid;}
    .radio {background: 520802; border-style: solid; border-color: 520802; color: 000000;}
    .rate {border-width: 0; color: 000000;}
    .check {background: 555555; border-width: 0; color: 000000;}
    </style>
    </head>
    <body bgcolor="#000000" text="#FFFFFF" link="#808080" vlink="#CCCCCC" alink="#FFFFFF">
    	<script language="javascript" type="text/javascript">
    	<!--
    	function get_username(obj)
    	{
    		var myval = obj[obj.selectedIndex].value; 
    		opener.document.post.username.value = myval
    	}
    	//-->
    	</script>
    	<form action="/search_user.php" method="post">
    	<input type="text" name="username" size="20">&nbsp;<input type="submit" name="submitted" value="Search">
    	<br><br><font size="1" face="verdana">Enter the full or partial username to search<br>
    	Use a * to search all usernames.</font><br>
    	</form>
    		<form name="search" method="post" action="/search_user.php">
    	<select name="theuser">
    			<option value="Defender">Defender</option>
    			<br>
    	<input type="submit" name="submit" value="Submit" onClick="get_username(this.form.theuser.options[this.form.theuser.selectedIndex].value)">
    	<br><font size="2" face="verdana"><a href="javascript:window.close()">Close Window</a></font></form>
    </body>
    </html>
    Last edited by Defender1; Jan 21, 2002 at 21:17.
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  9. #9
    SitePoint Zealot Drew630's Avatar
    Join Date
    Nov 2001
    Location
    Maryland
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In your code, you have this:

    <script language="javascript" type="text/javascript">
    <!--
    function get_username(obj)
    {
    var myval = obj
    [obj.selectedIndex].value;
    opener.document.post.username.value = myval
    }
    //-->
    </script>

    <form action="/search_user.php" method="post">
    <input type="text" name="username" size="20"> <input type="submit" name="submitted" value="Search">
    <br><br><font size="1" face="verdana">Enter the full or partial username to search<br>

    If you look at your input types, you'll see that your Java code asks for the value property of the input type username. However, looking at your input username, it doesn't have a value property.

    <input type="text" name="username" size="20">

    See, no value listed. If you want the value from submit, then you need to call for submit, not username.

    i.e. opener.document.post.SUBMIT.value = myval

    That is why you get that error. I suspect it was because you had both input lines on the same line. The best thing to do when coding, especially big projects, is to seperate your code with spaces and put comments in to idnetify what each piece does.

    Try changing that and see if that solves your problem.

    Drew
    ~Drew

    There Is No Greater Joy Than Soaring High On The Wings Of Your Dreams, Except Maybe The Joy Of Watching A Dreamer Who Has Nowhere To Land But In The Ocean Of Reality.

  10. #10
    SitePoint Addict
    Join Date
    May 2000
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Defender. The code example I gave you would be in the popup. It uses the onchange event to perform the javascript function when you select an option from the dropdown. If you want to use a button to perform that then you could use something like this:
    <html>
    <head>
    <title>3d artisan</title>
    <script language="javascript" type="text/javascript">
    <!--
    function get_username(myval)
    {
    opener.document.post.username.value = myval
    }
    //-->
    </script>
    </head>
    <body>
    <form name="search">
    <select name="theuser">
    <option value="Defender">Defender</option>
    <br>
    <input type="button" name="submit" value="Submit" onClick="get_username(document.search.theuser.options[document.search.theuser.selectedIndex].value)">
    <br><font size="2" face="verdana"><a href="java script:window.close()">Close Window</a>
    </font>
    </form>
    </body>
    </html>

    I cut down the code you supplied, but this should work. I don't believe you want to use an input type of submit to perform the function so I changed it to an input type of button. That is unless you also want to submit the form at the same time you populate your text field in the main window. When you click on the button it will grab the value from the option selected and pass it to the function. Also, you should put a check in there to insure that they selected something.

  11. #11
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Drew, that didn't work for me. It still said value was null or not an obj.

    request, that did work thanks.
    And no, I didn't want it as submit. It kept submitting the form. Thanks again.
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*


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
  •