Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


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

Posted on 2004-08-24
Medium Priority
Last Modified: 2008-02-01
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?
Question by:plasko
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 36

Expert Comment

ID: 11884295

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.


Expert Comment

ID: 11884376
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.


Expert Comment

ID: 11885604
Put this code in the popup window to reset the listbox

   function resetListBox()

<body onload="resetListBox()">

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 11886576
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.

Accepted Solution

trevorhartman earned 2000 total points
ID: 11886616
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

Expert Comment

ID: 11892359
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?

Author Comment

ID: 11909513
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.
LVL 19

Expert Comment

ID: 15646052
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to implement server side field validation and display customized error messages to the client.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question