Welcome to WebmasterWorld Guest from 54.242.105.196

Forum Moderators: open

JS: value from a pop-up to main window: undefined

javascript returns undefined, while the value should be from a hidden field

   
7:49 am on Aug 7, 2003 (gmt 0)

10+ Year Member



I'm no good at javascript, so I'm kinda clueless here.. after some messing around I've been able to get to do at least something, but the value I get on my main screen is "undefined".
help plz :(

in the pop-up script:

<form name="GebNaam">

<script language="JavaScript"><!--
function updateOpener() {
opener.document.Storing.vld_GebrNaam.value = document.GebNaam.hidden_GebrNaam.value;
opener.document.Storing.submit;
window.close();
}
//--></script>

<input type="hidden" value="<?php echo stripslashes($_SESSION['row']['GebrNaam']);?>" name="hidden_GebrNaam" size="1">
<?php
echo '<a href="javascript:updateOpener()" title="Gebruikersnaam">'.stripslashes($_SESSION['row']['GebrNaam']).'</a>';
?>

on my main screen there is a
<form name="Storing">
with a field vld_GebrNaam (type=input)

when I click on the link in the pop-up screen (defined in the php code), I expect the pop-up to close (that works) and that the value which belongs to the link (in the hidden field) will be placed in the input field vld_GebrNaam on the main screen

however.. the value from the pop-up is not transfered to the main screen, it shows up as "undefined".

why is it "undefined"?
as far as I can tell I'm doing it correctly now :(

9:35 am on Aug 7, 2003 (gmt 0)

10+ Year Member



should be-

opener.document.Storing.submit();

Maybe also try

moving the <script> outside the form tags.
using top.window.opener.document instead of opener

9:50 am on Aug 7, 2003 (gmt 0)

10+ Year Member



ok, I changed it.
also received a tip to insert an alert box to check the value. and indeed, the value the alert gives me is "undefined"
so the
document.GebNaam.hidden_GebrNaam.value
seems to be "undefined"

is there something wrong with that identifier then?

below is a part of the code of the pop-up script, as it is now.

<script language="JavaScript"><!--
function updateOpener() {
top.window.opener.document.Storing.vld_GebrNaam.value = document.GebNaam.hidden_GebrNaam.value;
window.close();
}
//--></script>

<form name="GebNaam" method=post>

<table summary="Overzicht werkstations" border="0" cellpadding="0" cellspacing="0" width="573">
<tr bgcolor=#6699cc>
<td width=2 class="normaletekst_alternatief"></td>
<td width=115 class="normaletekst_alternatief">Gebruiker</td>
<td width=150 class="normaletekst_alternatief">Vol.Naam</td>
<td width=140 class="normaletekst_alternatief">Afdeling</td>
<td width=166 class="normaletekst_alternatief">E-mail</td>
</tr>
<?php
for ($i = 0; $i < $num_results ; $i++)
{
$_SESSION['row'] = mysql_fetch_array($result);
?>
<tr>
<td class="kleinetekst_11">
</td>
<td class="kleinetekst_11">
<input type="hidden" value="<?php echo stripslashes($_SESSION['row']['GebrNaam']);?>" name="hidden_GebrNaam" size="1">
<script language="javascript">alert(document.GebNaam.hidden_GebrNaam.value);</script>
<?php
echo '<a href="javascript:updateOpener()" title="Gebruikersnaam">'.stripslashes($_SESSION['row']['GebrNaam']).'</a>';
?>
</td>
<td class="kleinetekst_11">
<?php echo stripslashes($_SESSION['row']['VolNaam']);?>
</td>
<td class="kleinetekst_11">
<?php echo stripslashes($_SESSION['row']['NaamAfd']);?>
</td>
<td class="kleinetekst_11">
<?php echo stripslashes($_SESSION['row']['EmailAd']);?>
</td>
</tr>
<?php

}
// <script language="javascript">alert(document.GebNaam.hidden_GebrNaam.value);</script>
?>
</table>
</form>

10:27 am on Aug 7, 2003 (gmt 0)

10+ Year Member



SOLUTION:

<script language="JavaScript"><!--
function updateOpener(valuetouse) {
window.opener.Storing.vld_GebrNaam.value = window.opener.Storing.vld_GebrNaam.value+ ' ' +valuetouse;
opener.document.Storing.submit;
window.close();
}
//--></script>

<form name="GebNaam" method=post>

<table summary="Overzicht werkstations" border="0" cellpadding="0" cellspacing="0" width="573">
<tr bgcolor=#6699cc>
<td width=2 class="normaletekst_alternatief"></td>
<td width=115 class="normaletekst_alternatief">Gebruiker</td>
<td width=150 class="normaletekst_alternatief">Vol.Naam</td>
<td width=140 class="normaletekst_alternatief">Afdeling</td>
<td width=166 class="normaletekst_alternatief">E-mail</td>
</tr>
<?php
for ($i = 0; $i < $num_results ; $i++)
{
$_SESSION['row'] = mysql_fetch_array($result);
?>
<tr>
<td class="kleinetekst_11">
</td>
<td class="kleinetekst_11">
<?php
//<script language="javascript">alert(document.GebNaam.hidden_GebrNaam.value);</script>
//echo '<a href="javascript:updateOpener()" title="Gebruikersnaam">'.stripslashes($_SESSION['row']['GebrNaam']).'</a>';
$loopvalue=stripslashes($_SESSION['row']['GebrNaam']);
echo "<a href=\"javascript:updateOpener('$loopvalue');\" title=\"Gebruikersnaam\">$loopvalue</a>";
?>
</td>
<td class="kleinetekst_11">
<?php echo stripslashes($_SESSION['row']['VolNaam']);?>
</td>
<td class="kleinetekst_11">
<?php echo stripslashes($_SESSION['row']['NaamAfd']);?>
</td>
<td class="kleinetekst_11">
<?php echo stripslashes($_SESSION['row']['EmailAd']);?>
</td>
</tr>
<?php

}
// <script language="javascript">alert(document.GebNaam.hidden_GebrNaam.value);</script>
?>
</table>
</form>

with kind thanks to " rfila "

 

Featured Threads

Hot Threads This Week

Hot Threads This Month