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!

Close child window and refresh form

Status
Not open for further replies.

GWINTO

IS-IT--Management
Nov 26, 2001
188
GB
I have a form that as part of its structure contains a number of list boxes, if the required field is not available within the list box contents, the user clicks an edit link which opens a new window containing a form to enter a new value for the list box. However when the child window is closed the form needs to be refreshed to re-populate the list box, adding the new value. This has the problem of losing all the previously entered data.

How can I refresh the list boxes without resetting the form?



The more you know, the more you realise there is to know....
CCNA MCP
 
on the sub form you can execute some client-side javascript...

theBox = window.opener.getElementById("selectID")
theBox.options[theBox.options.length] = new Option(optionValue, optionText)


you can fit this in and still have the pop window add the value to the DB that generates the main form...


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
 
Sorry to appear thick, can you simplify that, you've lost me!


The more you know, the more you realise there is to know....
CCNA MCP
 
make sure to rename selectID with the ID of the select list from the main page...

popPage.asp

<%
dim newCat, cn
newCat = replace(uCase(trim(request(&quot;newCat&quot;))), &quot;'&quot;,&quot;''&quot;)
if newCat <> &quot;&quot; then
set cn = server.createobject(&quot;adodb.connection&quot;)
cn.open application(&quot;connStr&quot;) 'or whatever connection string you're using...

cn.execute(&quot;INSERT INTO catTable VALUES ('&quot; & newCat & &quot;'&quot;)
%>
<script>
theBox = window.opener.getElementById(&quot;selectID&quot;)
theBox.options[theBox.options.length] = new Option('<%=newCat & &quot;','&quot; & newCat %>')
self.close()
<script>
<%
cn.close
set cn = nothing
response.end
end if
%>
ENTER NEW CATEGORY
<form action=&quot;popPage.asp&quot;>
<input name=&quot;newCat&quot;>
<input type=submit>
</form>

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
 
This isn't working, when I click the link to close the window nothing happens, if I put an Alert in the function to test it, that comes up fine so it is calling it.

Code is:

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



The more you know, the more you realise there is to know....
CCNA MCP
 
So you're passing a value to the popwindow to let it know which select? That value is server-side, you can't use it like that...

Also, where is the input box and the form? Please post your whole pop page...

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
 
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
 
My brain is a little fried right now...

Let's say you call your popwindow with the following code...

main.asp

<select id=&quot;trees&quot;>
<option value=1>Maple
<option value=2>Oak
<option value=3>Ash
</select>
Not in list? <a href=&quot;javascript: window.open('popPage.asp?selectID=trees')&quot;>Click Here</a>



popPage.asp

<%
dim newCat, cn, passedSelect
passedSelect = request(&quot;selectID&quot;)
newCat = replace(uCase(trim(request(&quot;newCat&quot;))), &quot;'&quot;,&quot;''&quot;)
if newCat <> &quot;&quot; then
set cn = server.createobject(&quot;adodb.connection&quot;)
cn.open application(&quot;connStr&quot;) 'or whatever connection string you're using...

cn.execute(&quot;INSERT INTO catTable VALUES ('&quot; & newCat & &quot;'&quot;)
%>
<script>
theBox = window.opener.getElementById(<%=passedSelect%>)
theBox.options[theBox.options.length] = new Option('<%=newCat & &quot;','&quot; & newCat %>')
self.close()
<script>
<%
cn.close
set cn = nothing
response.end
end if
%>
ENTER NEW CATEGORY
<form action=&quot;popPage.asp&quot;>
<input name=&quot;newCat&quot;>
<input type=hidden name=&quot;selectID&quot; value=&quot;<%=passedSelect%>&quot;>
<input type=submit>
</form>


Note that I write the value of the select list's ID into the form so that it can be used after the form is submitted (ie - the second time through).

Does this help?

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
 
No. I'm already using the correct selectID, in this case it is stratOb, I'm not passing it because I know what it is the variables are all filled as they be.

The code is not executing, why isn't it the window closing at least? window.close() is included.



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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top