A select dropdown. Whats the best event for this situation?

Imagine a select list with some options. When you select a particular option, a window might popup, or it might not, some options don't pop up a window, but in this case lets say it does, and you fill out some info. When you click done, the window closes, and some of the data you filled out is used to create a new option in the list, and set it as the selected option.

Right now, I have an onchange event looking to pop up the window. If the value of the select list is a certain thing, the window will pop up.

The problem comes when a person pops up the window, closes it (or loses it) and tries to do it again. Since the option is already selected, there is no change event, thus no popup.

I should also note that to find the box that popped up the window, I check for a select box with the value of the option that I know pops up windows. I was thinking of doing an onunload on the popup and setting it back to "Choose Options" (first option in the list) but that would change the select list even if they filled out the form and clicked done. Blah....

Any ideas?
Who is Participating?
trevorhartmanConnect With a Mentor Commented:
in your script in the pop you could define a global variable that holds the value of the select option.  after you define that, you could clear the dropdown.

var objDropDown = parent.opener.document.forms[0].mydropdown;
var selectedOption = objDropDown[objDropDown.selectedIndex].value;

objDropDown.selectedIndex = 0;


then in your handler function later, you can just refer to selectedOption

You could just have this on the select list:


but that would mess it up when you close the child window and set the selectedIndex to the new option. The only way I know if for you to do this:


This is hedging on the fact that if you close the popup and make a new option and select that one, then that's the last option. Of course, if you have a popup select as the last element, that could complicate things, but it's better.

in your window that pops you said you need the value of the option that caused the window to pop up.  after you get this value, can't you just set the dropdown.selectedIndex=0?  that way if the user closes the window they can reselect the option to pop the window again.

7 new features that'll make your work life better

It’s our mission to create a product that solves the huge challenges you face at work every day. In case you missed it, here are 7 delightful things we've added recently to monday to make it even more awesome.

Put this code in the popup window to reset the listbox

   function resetListBox()

<body onload="resetListBox()">

plaskoAuthor Commented:
The problem with riyasjef and trevor's solution is that I only even get the handle on the option at the time of adding the new data. If I change it before this (on load), I would really have no way to uniquely identify the select list that initiated the popup.

Due to the nature of the application, I could potentially have several dropdowns with the same name (but unique ids). I might need to just pass the id as a parameter, maybe. This may be my best solution. Unless someone can suggest a better one.
I would continue to use the onchange() event handler, when they close the popup window, you may want do a window.parent.reload() to refresh the parent page.  Are you using another technology to dynamically create the list box?  ASP, JSP?
plaskoAuthor Commented:
Yeah, I can't refresh the page. the whole reason I'm doing a pop-up is because I need to maintain state. But I think I like trevor's idea. just store off the handle, and reset it, then I'll have a handle on the select box. Don't know why that was so hard for me to figure out.

Thanks guys. I'll give it a go tomorrow, and close this question.
No comment has been added to this question in more than 21 days, so it is now classified as abandoned..
I will leave the following recommendation for this question in the Cleanup topic area:

ACCEPT trevorhartman  -- http://Q_21105600.html/#11886616

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

EE Cleanup Volunteer
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.