Solved

Dropdown List problem

Posted on 1998-05-01
10
137 Views
Last Modified: 2012-05-04
Hi All.

This is the first time I have used JavaScript, and Im stuck :)

I have two frames.  The top frame (called "top") has a drop down list box in it and a button.  Within this list is all the forms on my web page.  When I click the select button, the newly selected document is loaded in the whole window, not in the bottom frame (called "main").  

Im sure there is an easy way of doing this, but being new and all...  Enough of the excuses, right!

Please help :)
0
Comment
Question by:Stuart_Johnson
  • 4
  • 3
  • 3
10 Comments
 
LVL 6

Accepted Solution

by:
Holger101497 earned 100 total points
Comment Utility
well, since you haven't posted any of your code, I can't tell you exactly what's wrong, but there are twio things that seem obvious:

1) Don't call any of your frames "top" --- "top" is "kind of a reserved" word and refers to the highest-level-frame in the window (i.e. the whole window) --> that's probably (99% *g*) the reason your document is loaded in the whole window. Rename the frame to "topFrame" or to "navFrame" (navigation).

2) the command would/should be parent.main.location.href=whatever...

Let me know if that helps and post some code if it doesn't...
oh, btw: You said you were new - have you read the FAQ? You are not supposed to reject an answer just because it doesn't work 100% - just post another comment and I'll answer 'til it works (really shouldn't be too long :-). You can reject the answer if you feel that the "current expert" (i.e. me in this case :-) won't be able to help you solve your problem...

Good luck!
0
 
LVL 6

Author Comment

by:Stuart_Johnson
Comment Utility
I'll try that when I get home tonight.  Thanks.

I have been using EE for over 18 months now, so I am familiar with the methods of use.  Its just the first time I have used the Java area.

Stu.
0
 
LVL 6

Author Comment

by:Stuart_Johnson
Comment Utility
Holger,

Im still not having any luck with it.  Here is my original code.  Is that any help?

function testSelect(form){
        selection=form.list.selectedIndex;
 
        numEntries=8;
        myArray=new Array(numEntries);
        myArray.length=numEntries;
        myArray[0]="main.htm";
        myArray[1]="brief.htm";
        myArray[2]="screen_lo.htm";
        myArray[3]="screen_hi.htm";
        myArray[4]="wtintro.htm";
        myArray[5]="patches.htm";
        myArray[6]="content.htm";
        myArray[7]="utilities.htm";
        myArray[8]="wanted.htm";
        myArray[9]="suggestions.htm";
        myArray[10]="links.htm";
       
                        top.location.href=(myArray[selection]);
}

</script>

<form method="get" name="choice" target="main">
    <p align="right"><select name="list" size="1">
        <option>Main Page</option>
        <option>A brief overview</option>
        <option>Low resolution screen shots</option>
        <option>High resolution screen shots</option>
        <option>Walk Through - Virtual Database</option>
        <option>Patches and Pre-Releases</option>
        <option>Content Updates</option>
        <option>Utilities</option>
        <option>Wanted! Who Stuff!</option>
        <option>Suggestions and Comments</option>
        <option>Links to other Sites</option>
    </select> <input type="button" name="seek" value="Go!"
    onclick="testSelect(this.form)"></p>
</form>
</body>
</html>


Thanks for your help,

Stuart.
0
 

Expert Comment

by:rodm
Comment Utility
Stuart,

I took your code and found that it CAN WORK!  Here's the simple solution:

In your framesetter document, probably index.html (but maybe not) your code should look something like this:

..
..
..
<head>
<frameset  framespacing="0" border="0" rows="50,*">
      <frame src="menu.htm" name="topmenu" scrolling="no">
      <frame src="main.htm" name="main" scrolling="auto">
</frameset>
</head>
..
..
..
(NOTE the names of the frames I've set)

THEN, in your menu.html (holding the JavaScript) the ONLY change you need to make to your code to make it work is:

 window.parent.main.location.href=(myArray[selection]);

See, in Javascript, you have to go BACKWARDS to the PARENT window FIRST, then call the name of the frame that you assigned in the framesetter document.  You cannot call the name of the frame directly from the CHILD frame standpoint.

Holger is right about the word "top", but it is usually referred with an underscore "_top"... but in any case you should avoid words that are even similar to reserved words, just to be safe.

If you are satisfied with this comment, lemme know and perhaps it will be changed to an answer!

Good luck!
0
 

Expert Comment

by:rodm
Comment Utility
Stuart, something else kinda cool you could add to the code would be to eliminate the "GO!" button and have the pages load as soon as someone makes a selection from the drop-down list... it's simple, and here's the line to modify:

<select name="list" size="1" onchange="testSelect(this.form)">
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 6

Expert Comment

by:Holger101497
Comment Utility
First a quick note to rodm:
Since you're new I'll give you the benefit of doubt... if you had been at Experts-Exchange longer, I might be a little angry because what you're doing is effectively "stealing" this question (or at least trying it). Your saying that your comment might be changed into an answer means that my answer would have to be rejected. WHY?? You really don't say anything new! Of course you could be a little more specific because you could see the code, but the whole answer is in my two remarks!
* Also, you are NOT correct about "top". In HTML code, it is referred to as "_TOP", but in JavaScript, the variable is "top".
* Your second idea is good and I wanted to propose that as well, but you can't get rid of the "GO" button, because some browsers (e.g. IE3) don't support onchange for a Select-object which would effectively trap the user on the page.


Now for Stuart:
Being a good expert, I'll tell you much more than you asked for *g*
Most important thing first: Where is the problem? Look at my first answer and change "top.location.href=(myArray[selection]);" to "parent.main.location.href=(myArray[selection])". That should make your code work, but you should nevertheless rename your "top frame" to something other than "top", because "top" refers to the window and always causes trouble (but whom am I telling this? *g*)
Now some "added value": some remarks about your code and a much nicer solution:
1) numEntries=8;
   myArray=new Array(numEntries);
   myArray.length=numEntries;
That's not very efficient code. The second and third line do the same thing! And it's a thing you don't need to do at all...
All you need is myArray=new Array();
2) Also, take another look at your code: You create an array of 8 elements and then assign 11 elements to it!!
3) It's "cleaner" to pass the select-object instead of the form. The point of using functions is to make them flexible and they are not flexible if they always look for an element called "list".
4) Both "method=get" and "target=main" are useless, because the form is never actually submitted!
5) Those were just small remarks, here's a big one:
Each element in a select-object can have a "value" field!!
A very nice way of using this feature looks like this:
It's not only shorter, but also much easier to read and maintain (imagine inserting another item or rearranging them!)

     function testSelect(sel){
       nURL=sel.options[sel.selectedIndex].value;
       alert("Going to\n"+nURL);      
       parent.main.location.href=(myArray[selection]);
     }

     </script>

     <form method="get" name="choice" target="main" >
         <p align="right"><select name="list" size="1" onchange="testSelect(this)">
             <option value="main.htm">Main Page</option>
             <option value="brief.htm">A brief overview</option>
             <option value="screen_lo.htm">Low resolution screen shots</option>
             <option value="screen_hi.htm">High resolution screen shots</option>
             <option value="wtintro.htm">Walk Through - Virtual Database</option>
             <option value="patches.htm">Patches and Pre-Releases</option>
             <option value="content.htm">Content Updates</option>
             <option value="utilities.htm">Utilities</option>
             <option value="wanted.htm">Wanted! Who Stuff!</option>
             <option value="suggestions.htm">Suggestions and Comments</option>
             <option value="links.htm">Links to other Sites</option>
         </select> <input type="button" name="seek" value="Go!"
         onclick="testSelect(this.form.list)"></p>
     </form>

Good luck and have fun!
0
 

Expert Comment

by:rodm
Comment Utility
Lastly, a quick note to Holger:
I wasn't trying to "steal" a question, I was merely trying to help a person out — you should refrain from being so emotional.
I'm not in this for points; I'm in this to help. Please, continue your work with Stuart.  I'll leave this one alone.

Sorry, Stuart.
0
 
LVL 6

Expert Comment

by:Holger101497
Comment Utility
No problem at all... of course I wouldn't ask anybody not to post comments that might be helpful.
The only sentence that annoyed me was "...maybe this comment will be changed into an answer", because it really does imply rejecting my answer (which does answer the question).

I'm not in this for the points either and normally post much more than I'd have to to get the points. (what are points good for anyway?). However, if I anwer a question and don't like
a) the answer being rejected although it is correct and complete
b) If somebody adds two lines to one of my comments and posts it as an answer...

well.... take it easy :-)))
0
 
LVL 6

Author Comment

by:Stuart_Johnson
Comment Utility
HAY FELLAS!  Cool it down a bit.  I was after help, not a damn shooting match.  

Rodm:  Thank you for posting your comments.  I appreciate help, the more the better -  believe me, I need it :).  

Holger.  Again, I will try out your suggested answer.  I will get back too you in a couple of hours.  

Just so you know, I will NOT give points out to other people if someone has already posted a suggested answer.  I will reopen the question though if the answer does not work.  If someone then answered the question in a comment, I would ask them to post it as an answer.

I dont think rodm was trying to "steal" the question from you.  He was mearly opinionating constructive advise.  I do it quite often in the VB, Pascal, Delphi and Windows areas with no intention what so ever of taking someones glory from them.

Stuart.
0
 
LVL 6

Author Comment

by:Stuart_Johnson
Comment Utility
Thanks very much to both of you.  I now have it working :)

Stay tuned for more questions and annoyances.

Stu.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
This article discusses how to create an extensible mechanism for linked drop downs.
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…

743 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

15 Experts available now in Live!

Get 1:1 Help Now