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!

Child window not updating select list on parent form

Status
Not open for further replies.

GWINTO

IS-IT--Management
Nov 26, 2001
188
GB
A child window is opened from a form, with the intention of updating a select list, when a required value is not present, I only want the select list updated and not the whole form refreshed(reset) when the following code is run nothing is happening:

<script language=javascript>
function refreshlist(passedid)
{
alert(passedid);
var thebox=window.opener.document.getElementById(passedid);
alert(thebox.id)
thebox.options[thebox.options.length] = new Option('<%=idvalue & &quot;','&quot; & showValue %>');
alert(thebox.options.length)
window.close();
}

</script>
<div align=center><A HREF=&quot;javaScript:refreshlist('<%=selectid%>');&quot;>[Click here to close window]</A></div>

When the link is clicked, the first alert appears OK with the correct variable value showing, when viewing the source for the web page all other variables are filled as they should be.

However when the second alert box appears it is blank, when all the alert boxes are commented out the link does nothing, including not closing.

Is there a better way to update a form with out losing previously entered data? or why won't the above function work.

The more you know, the more you realise there is to know....
CCNA MCP
 
Finally figured something out here....

Seems windows doesn't like to create the Option object in a window other than where it's being used... Try this...


default.asp

<script>
function getPop(inVal){
window.open (&quot;pop.asp?selectid=&quot; + inVal)
}

function addOpt(inID, inText, inVal){
theSelect = document.getElementById(inID)
theSelect.options[theSelect.options.length] = new Option(inText, inVal)
}

</script>

<form name=&quot;myForm&quot;>
<select name=mySelect id=&quot;mySelect&quot;>
<option value=&quot;val1&quot;>Value 1
</select>

<input type=button onClick=&quot;getPop('mySelect')&quot; value=&quot;Add Option&quot;>
</form>


pop.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
%>
<script>
window.opener.addOpt('<%=passedSelect%>','<%=newCat%>','<%=newCat%>')
self.close()
</script>
<%

response.end
end if
%>
ENTER NEW CATEGORY
<form action=&quot;pop.asp&quot;>
<input name=&quot;newCat&quot;>
<input type=hidden name=&quot;selectID&quot; value=&quot;<%=passedSelect%>&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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top