• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 193
  • Last Modified:

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?
0
plasko
Asked:
plasko
1 Solution
 
ZylochCommented:
Hi

You could just have this on the select list:

onfocus="this.selectedIndex=0"

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:

onfocus="if(this.selectedIndex!=(this.options.length-1)){this.selectedIndex=0;}"

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.

Regards,
Zyloch
0
 
trevorhartmanCommented:
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.

-Trevor
0
 
riyasjefCommented:
Put this code in the popup window to reset the listbox

<script>
   function resetListBox()
   {
     window.opener.document.listBoxName.selectedIndex=0;
  }
</script>

<body onload="resetListBox()">


</body>
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
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.
0
 
trevorhartmanCommented:
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.

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

objDropDown.selectedIndex = 0;

</script>

then in your handler function later, you can just refer to selectedOption
0
 
FieldITCommented:
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?
0
 
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.
0
 
dakydCommented:
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.

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

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now