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!

Drop down box update from child window not working

Status
Not open for further replies.

GWINTO

IS-IT--Management
Nov 26, 2001
188
GB
The code below is for an asp page opened from a parent window. The parent contains a form with drop down box, if the entry that the user requires is not on the drop down list, then the user can click a link to open this window and create a new option for the list. I don't want the hole form refreshed when the user closes the child window, just the options in the particular drop down box, the code below should work but isn't, the broblem appears to be with the javascript because the entry is going in to the database fine, the alert box is showing but the window isn't closing or updating the options.

It uses a select case because it holds a hole host of similar updates
Between body tags:
<% casenum=request.querystring(&quot;casenum&quot;)
QU=&quot;','&quot;

Select case casenum

case 1: '----------- New Strategic Objective
response.write &quot;<b>New Strategic Objective</b>&quot;
response.write &quot;<form action='New.asp?casenum=4' method='post'>&quot;
response.write &quot;<input type=text name=stratOb size=30>&quot;
response.write &quot;<input type='reset' name='Reset' value='Reset'>&quot;
response.write &quot;<input type='submit' value='Submit'>&quot;
response.write &quot;</form>&quot;

case 4: '----Enter Strategic Objective into database
Response.write &quot;<b></b><br><br>&quot;
StratOb=request.form(&quot;StratOb&quot;)
createdby=request.servervariables(&quot;logon_user&quot;)
datein=now()

set rs=Server.CreateObject(&quot;adodb.Recordset&quot;) '------ This is to figure out what the ID number is for the value
connectme=&quot;DSN=intranet&quot;
sqlstmt= &quot;SELECT stratobID from stratobSABD Order by stratobid&quot;
rs.open sqlstmt, connectme
do while not rs.eof
stratobid=rs(&quot;stratobid&quot;)
rs.movenext
loop

set conn=server.createobject(&quot;adodb.connection&quot;)
conn.open &quot;intranet&quot;
sqlstmt = &quot;INSERT INTO stratobSABD(stratob,createdby,datein)&quot;
sqlstmt = sqlstmt & &quot; VALUES ('&quot; & stratob & QU & createdby & QU & datein& &quot;')&quot;
set rs=conn.execute(sqlstmt)
selectid=&quot;stratob&quot;
idvalue=stratobid+1
showvalue=stratob
done=1

End Select

If done=1 then %> '---only pass the update if its been done
<script language=javascript>
function refreshlist(passedid)
{
alert(&quot;Got here&quot;);
var thebox=window.opener.getElementById(passedid);
thebox.options[thebox.options.length] = new Option('<%=idvalue & &quot;','&quot; & showValue %>');
window.close();
}
</script>
<div align=center><A HREF=&quot;javaScript:refreshlist('<%=selectid%>');&quot;>[Click here to close window]</A></div>
<% else
response.write &quot;<div align=center><A HREF='JavaScript:window.close();'>[Click here to close window]</A></div>&quot;

When the source code is viewed after the page is run, all variables are filled as I expect:

function refreshlist(passedid)
{
//alert(&quot;Got here&quot;);
var thebox=window.opener.getElementById(passedid);
thebox.options[thebox.options.length] = new Option('33','test test');
window.close();
}
</script>
<div align=center><A HREF=&quot;javaScript:refreshlist('stratob');&quot;>[Click here to close window]</A></div>


The more you know, the more you realise there is to know....
CCNA MCP
 
try debuggin like this...

function refreshlist(passedid)
{
alert(passedid);
var thebox=window.opener.getElementById(passedid);
alert(thebox.id)
thebox.options[thebox.options.length] = new Option('33','test test');
alert(thebox.options.length
window.close();
}
</script>
<div align=center><A HREF=&quot;javaScript:refreshlist('stratob');&quot;>[Click here to close window]</A></div>

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

fart.gif
 
Done this and it displays the first alert box fine, with the correct value, I then commented out the first box and now nothing happens, so the problem appears to be at

var thebox=window.opener.getElementById(passedid);

Any ideas?

The more you know, the more you realise there is to know....
CCNA MCP
 
The value of &quot;passedid&quot; is correct also?
Add an alert(window.opener.location.href) to make sure that the opener object is correct...

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

fart.gif
 
Yes passedid returns the correct value

window.opener.location returns the correct URL for the parent window

window.opener.value returns unspecified

The more you know, the more you realise there is to know....
CCNA MCP
 
try

var thebox=window.opener.document.getElementById(passedid);


Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

fart.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top