homepage Welcome to WebmasterWorld Guest from 54.196.62.23
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
JS: value from a pop-up to main window: undefined
javascript returns undefined, while the value should be from a hidden field
Hilko

10+ Year Member



 
Msg#: 522 posted 7:49 am on Aug 7, 2003 (gmt 0)

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 :(

 

HocusPocus

10+ Year Member



 
Msg#: 522 posted 9:35 am on Aug 7, 2003 (gmt 0)

should be-

opener.document.Storing.submit();

Maybe also try

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

Hilko

10+ Year Member



 
Msg#: 522 posted 9:50 am on Aug 7, 2003 (gmt 0)

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>

Hilko

10+ Year Member



 
Msg#: 522 posted 10:27 am on Aug 7, 2003 (gmt 0)

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 "

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved