Welcome to WebmasterWorld Guest from 54.167.58.159

Forum Moderators: open

Message Too Old, No Replies

Drop Down JS problem

     

keyplyr

9:22 am on Mar 10, 2002 (gmt 0)

WebmasterWorld Senior Member keyplyr is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



I'm attempting to get the following external dropdown menu to default to "- I N D E X -" It does this when the script is written in the HTML but when I call it externally, it displays the second option (AP4J Home) instead. What am I doing wrong?

<!-- Hide the script from old browsers --
function surfto(form) {
var myindex=form.select1.selectedIndex
if (form.select1.options[myindex].value != "0") {
location=form.select1.options[myindex].value;}
}
document.writeln('<form>');
document.writeln('<SELECT NAME="select1" onChange="surfto(this.form)">');
document.writeln('<SIZE="1"');
document.writeln('<OPTION SELECTED VALUE="0"> - I N D E X - ');
document.writeln('<OPTION VALUE="index.html">AP4J Home');
document.writeln('<OPTION VALUE="page2.html">The Passion');
document.writeln('<OPTION VALUE="jazz_styles.html">Jazz Styles');
document.writeln('<OPTION VALUE="page3.html">Timeline');
document.writeln('<OPTION VALUE="eoj.html">Etymology');
document.writeln('<OPTION VALUE="dates.html">Milestones');
document.writeln('<OPTION VALUE="agdih.html">A Great Day in Harlem');
document.writeln('<OPTION VALUE="festivals.html">Festivals');
document.writeln('<OPTION VALUE="mags.html">Newsstand');
document.writeln('<OPTION VALUE="page1.html">Discussions & Searches');
document.writeln('<OPTION VALUE="page10.html">Jazz Artists Gallery');
document.writeln('<OPTION VALUE="webcasts.html">Webcasts');
document.writeln('<OPTION VALUE="juke.html">MIDI files');
document.writeln('<OPTION VALUE="page5.html">Music Instruction');
document.writeln('<OPTION VALUE="mtl.html">Music Teacher Locator');
document.writeln('<OPTION VALUE="page6.html">Basic Musicianship');
document.writeln('<OPTION VALUE="keys.html">Virtual Piano Chords');
document.writeln('<OPTION VALUE="page4.html">The Author');
document.writeln('<OPTION VALUE="site_tree.html">Site Tree');
document.writeln('<OPTION VALUE="page7.html">Other Sites');
document.writeln('</SELECT>');
document.writeln('</form>');
//-->

tedster

2:35 pm on Mar 10, 2002 (gmt 0)

WebmasterWorld Senior Member tedster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



In the third doucment.writeIn statement, the SIZE tag has no ">".

keyplyr

7:07 pm on Mar 10, 2002 (gmt 0)

WebmasterWorld Senior Member keyplyr is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Thank you Tedster. I musta stared at that for an hour attempting to find the error. Amazing what a different set of eyeballs can easily notice.

keyplyr

8:19 pm on Mar 10, 2002 (gmt 0)

WebmasterWorld Senior Member keyplyr is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Another question if I may; the script works, but would it not be better to include the SIZE attribute inside the SELECT tag, like this:

document.writeln('<SELECT NAME="select1" onChange="surfto(this.form)" SIZE="1">');

I'm thinking NN and also saving a document.writeIn.

tedster

9:20 pm on Mar 10, 2002 (gmt 0)

WebmasterWorld Senior Member tedster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Yes, that's where it belongs -- SIZE is an attribute and not an element in its own right.

The default value for SELECT is 1 in most browsers, and that's why the current code seems to get the result you're aiming for. The browser is just ignoring the SIZE tag, which you can see by changing the number to "3" -- you still get 1 option at a time.

(edited by: tedster at 10:55 pm (utc) on Mar. 10, 2002)

keyplyr

9:36 pm on Mar 10, 2002 (gmt 0)

WebmasterWorld Senior Member keyplyr is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Thanks again