Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Popup and retrieval of values

Status
Not open for further replies.

runcsmeduncs

Programmer
Aug 10, 2004
5
GB
I have a form that launches a popup when the user clicks on an anchor link.
The html for the popup looks like this:

<html>
<head>
<script language="JavaScript" type="text/javascript">
function passBack(x)
{
opener.document.frmdept_submit.p_dept.value= x;
opener.document.frmdept_submit.p_dept.focus();
close();
}
</script>
</head>
<body>
<TABLE >
<TR>
<TD> DEPT </TD>
<TD> DESC </TD>
</TR>
<TR>
<TD> <A HREF="javascript:passBack('1258');">1258</A> </TD>
<TD> <A HREF="javascript:passBack('1258');">IT Department</A> </TD>
</TR>
<TR>
<TD> <A HREF="javascript:passBack('5897');">5897</A> </TD>
<TD> <A HREF="javascript:passBack('5897');">HR Department</A> </TD>
</TR>
</TABLE>
</body>
</html>

As you can see there is a JS function called passBack which accepts 1 input variable (x). Basically all this function does whn called in the body of the html document, is to set the value of the input box "p_dept" to the value specified and set focus to that input box.

This works fine when the form hsa only one row in it as there is only one input box called "p_dept".

When there are more than 1 row (and there may be many) there are multiple existances of "p_year" and the passBack function does not know which box to return the value to.

Could someone please provide me some help in how I can get the passBack function to work when I have more than 1 row in my form (frmdept_submit).

Thanks in advance
 
That is not an option because my html form is built up in a PL/SQL cursor FOR loop.

They need to be called the same name because the array p_dept is processed in further PL/SQL procedures sitting behind the form.

For this reason i need to either pass an array into the JS function or reference individual elements on the form in the JS passBack function, something I am not sur how to do.
 

To fill in the last input you could use something like this:
Code:
	function passBack( x ) {

		var allInputs = opener.document.getElementsByName( "p_dept" );
		var theInput = allInputs[ allInputs.length - 1 ];
		theInput.value = x;
		theInput.focus();
		self.close();
	}

But is it always the last one? If not, with the names all the same, how are you meant to tell the difference?
 
Thats getting better but I need to change all and not just the last one.

Is there some way of altering your code so that it processes the row in the for that the user selects.

Currently when i run the popup after clicking on the anchor in row 1, your code changes the value in row 2 of p_dept.

I would like the popup to change the value in the row where the anchor link is clicked.

Thanks
 

Sure, it ain't hard. Would be handy to see some example code though. Say of a row in the parent window ...

Is it actually a table row? Is there an ID we can reference? It'll save us asking all these questions if we can see the code.
 
yep no worries a sample bit of table code looks like this:

<HTML>
<BODY>
<form name="frmdept_submit" action="" method="POST">
<table border="1" cellpadding="1">
<tr>
<td>Staff ID</td>
<td>Dept</td>
</tr>
<tr>
<TD> 9854758 </TD>
<TD>
<INPUT TYPE="text" NAME="p_dept" SIZE="8" MAXLENGTH="6" VALUE="1245">
<A HREF="javascript:deptsearch('frmdept_submit','p_dept')">Popup</A> </TD>
</tr>
<tr>
<TD> 4458745 </TD>
<TD>
<INPUT TYPE="text" NAME="p_dept" SIZE="8" MAXLENGTH="6" VALUE="8547">
<A HREF="javascript:deptsearch('frmdept_submit','p_dept')">Popup</A> </TD>
</tr>
</TABLE>
<INPUT TYPE="submit" VALUE="Update">
</FORM>
</BODY>
</HTML>


The javascript call to deptsearch is my popup which i am trying to get working.

Hope that is enough info for now
 
You should be able to reference the named elements using getElementsByName:

Code:
var myInputs = document.getElementsByName('p_year'); // returns a collection of controls
alert(myInputs[0].value);
alert(myInputs[1].value);
... etc ...

Hope this helps,
Dan
 

Right, if you set a global variable in the parent window called currentEl that holds the last link clicked then you can just reference the relevant input.

theInput = opener.currentEl.parentNode.getElementsByTagName( "input" )[ 0 ];

HTH.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top