Accessing dropdown list from a popup

I have a dropdown select list on my page with a list of images. A user can either select one of these or choose to add a new one. If they add a new one, then a popup is loaded.

I have sorted everything in regards to adding the image, I just want the value to be passed back into the dropdown at the last step.

Currently the value is passed back and changes the background of a div to display the new image, I just can't seem to pass the value into the dropdown.

I'm using the following, it's the top one that doesn't work:

<script language="javascript" type="text/javascript">
<!--
window.opener.document.getElementById('piclist').value='top_<%=request.form("imagePath")%>';
window.opener.document.getElementById('top_pic').style.background='url(top/top_<%=request.form("imagePath")%>)';
//-->
</script>

Thanks

Chris
djfenomAsked:
Who is Participating?
 
hieloConnect With a Mentor Commented:
try adding this to your parent page:
function addToList(elem,value,text){
	var l = document.getElementById(elem);
	if( !l )
	{
		alert("Invalid element ID provided");
		return false;
	}
	l.options[l.options.length]=new Option(text,value);
return true;
}
 
 
then in the popup use:
<script type="text/javascript">
window.opener.addToList('piclist','top_<%=request.form("imagePath")%>','top_<%=request.form("imagePath")%>');
window.opener.document.getElementById('top_pic').style.background='url(top/top_<%=request.form("imagePath")%>)';
</script>

Open in new window

0
 
hieloCommented:
are you saying you are trying to add it to the dropdown list? Is so try:
var l = window.opener.document.getElementById('piclist');
l.options[l.options.length] = new Option('top_<%=request.form("imagePath")%>','top_<%=request.form("imagePath")%>');
window.opener.document.getElementById('top_pic').style.background='url(top/top_<%=request.form("imagePath")%>)';

Open in new window

0
 
jose_juanCommented:
Hi,

probably your code are running before the content are available. Try to execute your code after onload event.

On the other hand, if you select the image reloading the page, why not set the image background on style attribute? like this

...<div style="background-image: url(<%=image%>)">...

Good luck!
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
djfenomAuthor Commented:
Thank hielo, basically on the parent page I have a form that needs to be submitted and the dropdown list displays all of the images in a particular folder using FileSystemObject. When a new image is added I need this image to be selected in the dropdown so when the form is submitted this is passed on to the next page.

I tried your suggestion, but it only changed the image.
0
 
djfenomAuthor Commented:
I don't really want to have to reload the parent page as the user will have filled out a section of the form already.
0
 
hieloCommented:
this:
var l = window.opener.document.getElementById('piclist');
l.options[l.options.length] = new Option('top_<%=request.form("imagePath")%>','top_<%=request.form("imagePath")%>');

assumes that you have a select list with id="piclist". Not sure if your piclist is a select or a textbox, but use whatever id your select list has.
0
 
djfenomAuthor Commented:
That gives the same result and it also stops the background image changing.

This is my select on the parent page:

<select name="piclist" id="piclist" style="width:270px;" onchange="document.getElementById('top_pic').style.background = 'url(top/'+this.value+')'">
        <option value="top-image01.jpg">Please Select</option>
        <%
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set rootFolder = fso.GetFolder(Server.MapPath("/top"))

Set files = rootFolder.Files

For Each file in files
      if file.Name = "blank.gif" OR file.Name = "transparent.gif" then
      else
    Response.Write "<option value=""" & file.Name & """>" & file.Name & "</option>" & vbCrLf
      end if
Next
%>
      </select>
0
 
hieloCommented:
>>I tried your suggestion, but it only changed the image.
did it add the image to the list? I am trying to guess if it just NOT "select" the added image.
0
 
djfenomAuthor Commented:
No, the image isn't added to the list or selected?
0
 
djfenomAuthor Commented:
Right, that gets added to the list, but how do I get it selected?

Thanks
0
 
hieloCommented:
try:
l.options[l.options.length]=new Option(text,value,true);
0
 
djfenomAuthor Commented:
No, that still gives the same result.
0
 
hieloCommented:
l.options[l.options.length]=new Option(text,value,false,true);
0
 
djfenomAuthor Commented:
Awesome!

Thanks very much!
0
 
hieloCommented:
you are welcome
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.