SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict adam2003w's Avatar
    Join Date
    Mar 2004
    Location
    colorado
    Posts
    396
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Pass Value From Popup Window to Parent Window w/Multiple Forms?

    Pass Value From Popup Window to Parent Window w/Multiple Forms?

    I've found some great forum posts on passing a value from a pop-up window to a parent window. For example:

    Populating form boxes from a popup window link

    My question is how can I pass the value(s) from a popup window to a parent window that has multiple similar forms?

    My parent page has a form that repeats multiple times (see attached image) that is handling various records of data. Can I pass which form (like form1, form2, form3) I want the values passed to? Or even better can I pass which record (like unique_record1, unique_record2, etc.) I want the values passed to?

    Thanks in advance.
    Attached Images Attached Images

  2. #2
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Since you're so nice about it...
    Code:
    <html>
    <head>
    <title>Form Page</title>
    <style type="text/css">
    form {font-weight:bold;float:left;margin-left:12px;}
    a:link {font:bold 14px verdana;color:white;}
    a:visited {font:bold 14px verdana;color:skyblue;}
    a:hover {font:bold 14px verdana;letter-spacing:2px;}
    a:active {font:bold 14px verdana;color:lightblue;}
    </style>
    <script type="text/javascript">
    
    var Fwin = null;
    var w = 300;
    var h = 100;
    var l = (screen.availWidth - w) * .5;
    var t =  20;
    
    function openFormWin(url)
    {
    	Fwin = open(url,'Fwin','width='+w+',height='+h+',left='+l+',top='+t+',status=0');
    	if (Fwin && !Fwin.closed)
    		Fwin.focus();
    	return false;
    }
    
    </script>
    </head>
    <body style="background:steelblue;" onload="document.forms[0].reset();document.forms[1].reset();document.forms[2].reset()">
    <br>
    <a href="#null" onclick="return openFormWin('foo.html')">Show Choices</a>
    <br><br>
    <form id="multi1">multi1<br><br>
    <input name="user_name" type="text">___name<br>
    <input name="user_address" type="text">___address<br>
    <input name="user_city" type="text">___city<br>
    <input name="user_state" type="text">___state<br><br>
    <select name="country">
    <option selected="selected">-- country --</option>
    <option value="USA">USA</option>
    <option value="Scotland">Scotland</option>
    <option value="Romania">Romania</option>
    </select>___country<br><br>
    <select name="potatoes" multiple="multiple" size="3">
    <option value="fried">fried</option>
    <option value="baked">baked</option>
    <option value="burned">burned</option>
    </select>___potatoes<br><br>
    ___temperature<br>
    &nbsp;&nbsp;&nbsp;<input name="temp" type="radio" value="hot"> hot<br>
    &nbsp;&nbsp;&nbsp;<input name="temp" type="radio" value="cold"> cold<br><br>
    ___yes? <input name="yes" type="checkbox" value="yes"><br>
    ___no! <input name="no" type="checkbox" value="yes">
    </form>
    <form id="multi2">multi2<br><br>
    <input name="user_name" type="text">___name<br>
    <input name="user_address" type="text">___address<br>
    <input name="user_city" type="text">___city<br>
    <input name="user_state" type="text">___state<br><br>
    <select name="country">
    <option selected="selected">-- country --</option>
    <option value="USA">USA</option>
    <option value="Scotland">Scotland</option>
    <option value="Romania">Romania</option>
    </select>___country<br><br>
    <select name="potatoes" multiple="multiple" size="3">
    <option value="fried">fried</option>
    <option value="baked">baked</option>
    <option value="burned">burned</option>
    </select>___potatoes<br><br>
    ___temperature<br>
    &nbsp;&nbsp;&nbsp;<input name="temp" type="radio" value="hot"> hot<br>
    &nbsp;&nbsp;&nbsp;<input name="temp" type="radio" value="cold"> cold<br><br>
    ___yes? <input name="yes" type="checkbox" value="yes"><br>
    ___no! <input name="no" type="checkbox" value="yes">
    </form>
    <form id="multi3">multi3<br><br>
    <input name="user_name" type="text">___name<br>
    <input name="user_address" type="text">___address<br>
    <input name="user_city" type="text">___city<br>
    <input name="user_state" type="text">___state<br><br>
    <select name="country">
    <option selected="selected">-- country --</option>
    <option value="USA">USA</option>
    <option value="Scotland">Scotland</option>
    <option value="Romania">Romania</option>
    </select>___country<br><br>
    <select name="potatoes" multiple="multiple" size="3">
    <option value="fried">fried</option>
    <option value="baked">baked</option>
    <option value="burned">burned</option>
    </select>___potatoes<br><br>
    ___temperature<br>
    &nbsp;&nbsp;&nbsp;<input name="temp" type="radio" value="hot"> hot<br>
    &nbsp;&nbsp;&nbsp;<input name="temp" type="radio" value="cold"> cold<br><br>
    ___yes? <input name="yes" type="checkbox" value="yes"><br>
    ___no! <input name="no" type="checkbox" value="yes">
    </form>
    </body>
    </html>
    [foo.html]
    Code:
    <html>
    <head>
    <title>CHOOSER</title>
    <style type="text/css">
    a:link {font:bold 12px verdana;color:navy;}
    a:visited {font:bold 12px verdana;color:blue;}
    a:hover {font:bold 12px verdana;letter-spacing:2px;}
    a:active {font:bold 12px verdana;color:white;}
    </style>
    <script type="text/javascript">
    
    Object.prototype.toString = function() //helper method, remove
    {
    	var prop, str = '';
    	for (prop in this)
    		str += prop + ': ' + this[prop] + '\n';
    	return str;	
    }
    
    var autoclose = false; //close window
    
    var transferVals = new Array();
    
        transferVals[0] = {
    			user_name: 'Al Sharpton' ,
    			user_address: '33 Windy Lane' ,
    			user_city: 'Paramus' ,
    			user_state: 'NJ' ,
    			country: 'USA' ,
    			potatoes: [ 'fried' , 'baked' , 'burned' ] ,
    			temp: 'hot' ,
    			yes: 'yes'
    		      }
        transferVals[1] = {
    			user_name: 'Joe Z. Blow' ,
    			user_address: '16 Park Crescent' ,
    			user_city: 'Shmeck' ,
    			country: 'Romania' ,
    			potatoes: 'burned' ,
    			temp: 'cold' ,
    			no: 'no'
    		      }
        transferVals[2] = {
    			user_name: 'Dracula' ,
    			user_address: '11 Jugular Court' ,
    			user_city: 'Klarn' ,
    			country: 'Scotland' ,
    			potatoes: 'baked' ,
    			temp: 'hot'
    		      }
    
    function to_opener(form_id, oVals)
    {
    	if (!opener || opener.closed || null == opener.document.getElementById(form_id))
    		return false;
    	var oOpenerForm = opener.document.getElementById(form_id);
    	oOpenerForm.reset(); //clear form
    	var fieldname, opt, i, j, optVal, selArr, opener_els = oOpenerForm.elements;
    	for (fieldname in oVals)
    	{
    		if (obj = opener_els[fieldname])
    		{
    			if (typeof obj[0] == 'undefined' || /select/.test(obj.type))
    				el = obj;
    			else el = obj[0];
    			switch (el.type)
    			{
    				case 'text' :
    				case 'textarea' :
    				case 'hidden' :
    					el.value = oVals[fieldname];
    					break;
    				case 'checkbox' :
    				case 'radio' :
    					grp = opener_els[el.name]; i = 0;
    					if (typeof grp[0] == 'undefined') 
    						opener_els[fieldname].checked = true;
    					else while (el = grp[i++]) 
    						if (el.value == oVals[fieldname])
    							el.checked = true;
    					break;
    				case 'select-one' :
    					i = 0;
    					while (opt = el.options[i++])
    						if (opt.value == oVals[fieldname])
    							opt.selected = true;
    					break;
    				case 'select-multiple' :
    					if (typeof oVals[fieldname] == 'string')
    						selArr = [oVals[fieldname]];
    					else selArr = oVals[fieldname];
    					i = 0;
    					while (optVal = selArr[i++])
    					{
    						j = 0;
    						while (opt = el.options[j++])
    							if (opt.value == optVal)
    								opt.selected = true;
    					}
    					break;
    			}
    		}
    	}
    	if (autoclose)
    		self.close();
    	return false;        
    }
    
    </script>
    </head>
    <body style="text-align:center;background:#82a4c8;">
    <a href="#null" onclick="alert(transferVals[0]);return to_opener('multi1',transferVals[0])">form multi1</a><br /><br />
    <a href="#null" onclick="alert(transferVals[1]);return to_opener('multi2',transferVals[1])">form multi2</a><br /><br />
    <a href="#null" onclick="alert(transferVals[2]);return to_opener('multi3',transferVals[2])">form multi3</a>
    </body>
    </html>
    hth....
    ::: certified wild guess :::


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
  •