SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Hybrid View

  1. #1
    SitePoint Evangelist
    Join Date
    Dec 2000
    Posts
    528
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Link in new window changing value of <input> in parent window

    Hi everybody,

    I'm very new to JavaScript, and need your help.

    I'm building a program for webmasters, and I need to have it so that I can have an <INPUT> button that, when clicked, will open up a new window (400x350 pixels) with a list of links. However, when the person clicks one of those links, the window closes, the value of an <input type="text" name="parentdoc" size="8" maxlength="8" readonly> is updated.

    How would I accomplish this?

    (As I mentioned above, I am very new to JavaScript, so please provide as much explanation and code as possible.)

    Thanks in advance,
    Corbb O'Connor
    Looking for quality website design or database programming?
    Contact me for more information and a FREE quote!

  2. #2
    SitePoint Wizard silver trophy Jeremy W.'s Avatar
    Join Date
    Jun 2001
    Location
    Toronto, Canada
    Posts
    9,123
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Okay, in the new window do this:

    Code:
    <script language="javascript" type="text/js">
    <!--
    
    function doPop(formname,formitem,newvalue,close)
    {
    	window.opener.formname.formitem.value=newvalue;
    	if(close=="yes")
    	{
    		window.close();
    	}
    }
    
    // -->
    </script>
    And you'd use it like this:

    Code:
    <a href="#" onClick="doPop('form1','parentdoc','test','yes');">test link</a>
    Cool?
    SVP Marketing, SoCast SRM
    Personal blog: Strategerize
    Twitter: @jeremywright

  3. #3
    SitePoint Evangelist
    Join Date
    Dec 2000
    Posts
    528
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Jeremy,

    Thanks for your help.

    In the form (in the window "below" the popup window), how would I use <input type="submit"...> to open up the new window with all the links?

    Thanks again,
    Corbb O'Connor
    Looking for quality website design or database programming?
    Contact me for more information and a FREE quote!

  4. #4
    SitePoint Wizard silver trophy Jeremy W.'s Avatar
    Join Date
    Jun 2001
    Location
    Toronto, Canada
    Posts
    9,123
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    1. <input type="button" value="Submit" onClick="[window.open() code, see 2];">
    2. Go to www.studiococo.com/custom.asp?window.asp for Window Builder code you can customize
    SVP Marketing, SoCast SRM
    Personal blog: Strategerize
    Twitter: @jeremywright

  5. #5
    SitePoint Evangelist
    Join Date
    Dec 2000
    Posts
    528
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Talking Thanks!

    Jeremy,

    Thank you very much!

    (Cool site by the way!)
    Corbb O'Connor
    Looking for quality website design or database programming?
    Contact me for more information and a FREE quote!

  6. #6
    SitePoint Wizard silver trophy Jeremy W.'s Avatar
    Join Date
    Jun 2001
    Location
    Toronto, Canada
    Posts
    9,123
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    n-n-n-n-n-n-o problem
    SVP Marketing, SoCast SRM
    Personal blog: Strategerize
    Twitter: @jeremywright

  7. #7
    SitePoint Evangelist
    Join Date
    Dec 2000
    Posts
    528
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Slight problem...

    Hi,

    I have the two files eetup: The first one (which calls the popup works just fine)
    Code:
    <!--code for page1.html-->
    <html>
    <head>
    <title>Page One</title>
    </head>
    <body>
    
    <form name="form1" action="" method="post">
    <input type="text" name="parentdoc" value="" readonly>
    
    <input type="submit" onClick="var page2=window.open('page2.html','page2','width=400,height=100,top=0,left=5,menu=yes,toolbar=no,directories=no,status=yes,scrollbars=yes,resizable,dependent=no');">
    
    </body>
    </html>
    And the page that is "popped up" (which doesn't work)
    Code:
    <!--code for page2.html-->
    <html>
    <head>
    <title>Page Two</title>
    
    <script language="javascript" type="text/js">
    <!--
    
    function doPop(formname,formitem,newvalue,close)
    {
    	window.opener.formname.formitem.value=newvalue;
    	if(close=="yes")
    	{
    		window.close();
    	}
    }
    
    // -->
    </script>
    </head>
    <body>
    
    <a href="#" onClick="doPop('form1','parentdoc','5','yes');">TEXT_TO_BE_DISPLAYED_FOR_LINK</a>
    
    </body>
    </html>
    Internet Explorer says that there is a problem on page2.html, on the bolded line. Internet Explorer says, "Object expected."

    How can I fix this?

    Thanks in advance,
    Corbb O'Connor
    Looking for quality website design or database programming?
    Contact me for more information and a FREE quote!


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
  •