djfenom
asked on
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.get ElementByI d('piclist ').value=' top_<%=req uest.form( "imagePath ")%>';
window.opener.document.get ElementByI d('top_pic ').style.b ackground= 'url(top/t op_<%=requ est.form(" imagePath" )%>)';
//-->
</script>
Thanks
Chris
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.get
window.opener.document.get
//-->
</script>
Thanks
Chris
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!
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!
ASKER
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.
I tried your suggestion, but it only changed the image.
ASKER
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.
this:
var l = window.opener.document.get ElementByI d('piclist ');
l.options[l.options.length ] = new Option('top_<%=request.for m("imagePa th")%>','t op_<%=requ est.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.
var l = window.opener.document.get
l.options[l.options.length
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.
ASKER
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.getElem entById('t op_pic').s tyle.backg round = 'url(top/'+this.value+')'" >
<option value="top-image01.jpg">Pl ease Select</option>
<%
Set fso = Server.CreateObject("Scrip ting.FileS ystemObjec t")
Set rootFolder = fso.GetFolder(Server.MapPa th("/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>
This is my select on the parent page:
<select name="piclist" id="piclist" style="width:270px;" onchange="document.getElem
<option value="top-image01.jpg">Pl
<%
Set fso = Server.CreateObject("Scrip
Set rootFolder = fso.GetFolder(Server.MapPa
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>
>>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.
did it add the image to the list? I am trying to guess if it just NOT "select" the added image.
ASKER
No, the image isn't added to the list or selected?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Right, that gets added to the list, but how do I get it selected?
Thanks
Thanks
try:
l.options[l.options.length ]=new Option(text,value,true);
l.options[l.options.length
ASKER
No, that still gives the same result.
l.options[l.options.length ]=new Option(text,value,false,tr ue);
ASKER
Awesome!
Thanks very much!
Thanks very much!
you are welcome
Open in new window