homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

Drop Down JS problem

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

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") {
document.writeln('<SELECT NAME="select1" onChange="surfto(this.form)">');
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');



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

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


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

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.


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

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.


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

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)


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

Thanks again

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved