Solved

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

Posted on 2004-08-24
10
180 Views
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?
0
Comment
Question by:plasko
10 Comments
 
LVL 36

Expert Comment

by:Zyloch
ID: 11884295
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
 
LVL 8

Expert Comment

by:trevorhartman
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.

-Trevor
0
 
LVL 9

Expert Comment

by:riyasjef
ID: 11885604
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
 

Author Comment

by:plasko
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.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 8

Accepted Solution

by:
trevorhartman earned 500 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.

<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
 
LVL 1

Expert Comment

by:FieldIT
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?
0
 

Author Comment

by:plasko
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.
0
 
LVL 19

Expert Comment

by:dakyd
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.

dakyd
EE Cleanup Volunteer
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now