52 users online (1 members and 51 guests)  


  Results 1 to 5 of 5

Related

  1. Javascript Function    Forum: Javascript Forum
    Replies: 0
  2. HTML Function    Forum: Javascript Forum
    Replies: 2
  3. die function    Forum: CGI Perl Forum
    Replies: 2
  4. Minimizing Rube Goldfarbian functions    Forum: Javascript Forum
    Replies: 3
  1. #1
    benzden's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Feb 2002
    Location
    San Antonio, Texas
    Posts
    652

    Another Rube Goldfarb function of mine

    Now, if I were writing this in a language like PowerBasic, I'd define one array with the full name, create the ID array as an all lower case subset of the first four digits and change the value of the 'head' array item to allcaps with a red vs blue color. Here's the klunky way I've done it to display at http://Homes.ShermanBlvd.com (my 1020th web page):
    Code:
    /*  <SCRIPT LANGUAGE="JavaScript">sbnav('lisb')</SCRIPT> */
    function sbnav(head) {
    var test=head + " "
    j=test.length
    if (j<=1||test=="undefined "||head=="help") { fend=" " }
     else { fend= "<HR ID=18gr NOSHADE SIZE=1 WIDTH=76%>" }
    var head0  = "Lisbon"    ; var fil0 = "<A ID=notbl1 HREF=#" ;
    var head1  = "Spaulding" ; var fil1 = " " + fil0 ;
    var head2  = "Garfield"  ; var fil2 = fil1 ;
    var head3  = "North"     ; var fil3 = fil1 ;
    var head4  = "Meinecke"  ; var fil4 = fil1 ;
    var head5  = "Wright"    ; var fil5 = fil1 ;
    var head6  = "Clarke"    ; var fil6 = "<BR>" + fil0 ;
    var head7  = "Center"    ; var fil7 = fil1 ;
    var head8  = "Hadley"    ; var fil8 = fil1 ;
    var head9  = "Locust"    ; var fil9 = fil1 ;
    var head10 = "Chambers"  ; var fil10= fil1 ;
    var head11 = "Burleigh"  ; var fil11= fil1 ;
    var head12 = "Auer"      ; var fil12= "<BR>" + fil0 ;
    var head13 = "Bonny"     ; var fil13= fil1 ;
    var head14 = "Sieben"    ; var fil14= fil1 ;
    var head15 = "Concordia" ; var fil15= fil1 ;
    var head16 = "Bernhard"  ; var fil16= fil1 ;
    var head17 = "Townsend"  ; var fil17= fil1 ;
    var head18 = "Keefe"     ; var fil18= "<BR>" + fil0 ;
    var head19 = "Nash"      ; var fil19= fil1 ;
    var head20 = "Roosevelt" ; var fil20= fil1 ;
    var head21 = "Ridge"     ; var fil21= fil1 ;
    var head22 = "Capitol"   ; var fil22= fil1 ;
    var fill = "<A ID=notrd4 HREF=#" ; var filw = " " + fill ;
         if (head == "lisb") { fil0 = fill  }
    else if (head == "spau") { fil1 = filw  }
    else if (head == "garf") { fil2 = filw  }
    else if (head == "nort") { fil3 = filw  }
    else if (head == "mein") { fil4 = filw  }
    else if (head == "wrig") { fil5 = filw  }
    else if (head == "clar") { fil6 = "<BR>" + fill  }
    else if (head == "cent") { fil7 = filw  }
    else if (head == "hadl") { fil8 = filw  }
    else if (head == "locu") { fil9 = filw  }
    else if (head == "cham") { fil10= filw  }
    else if (head == "burl") { fil11= filw  }
    else if (head == "auer") { fil12= "<BR>" + fill  }
    else if (head == "bonn") { fil13= filw  }
    else if (head == "sieb") { fil14= filw  }
    else if (head == "conc") { fil15= filw  }
    else if (head == "bern") { fil16= filw  }
    else if (head == "town") { fil17= filw  }
    else if (head == "keef") { fil18= "<BR>" + fill  }
    else if (head == "nash") { fil19= filw  }
    else if (head == "roos") { fil20= filw  }
    else if (head == "ridg") { fil21= filw  }
    else if (head == "capi") { fil22= filw  }
    fill = "</A> " + fill
    document.write("<A NAME=" + head + "><P><TT ID=notrd6>[Intersection]</TT><BR>"
    + fil0  + "lisb>" + head0
    + fil1  + "spau>" + head1
    + fil2  + "garf>" + head2
    + fil3  + "nort>" + head3
    + fil4  + "mein>" + head4
    + fil5  + "wrig>" + head5
    + fil6  + "clar>" + head6
    + fil7  + "cent>" + head7
    + fil8  + "hadl>" + head8
    + fil9  + "locu>" + head9
    + fil10 + "cham>" + head10
    + fil11 + "burl>" + head11
    + fil12 + "auer>" + head12
    + fil13 + "bonn>" + head13
    + fil14 + "sieb>" + head14
    + fil15 + "conc>" + head15
    + fil16 + "bern>" + head16
    + fil17 + "town>" + head17
    + fil18 + "keef>" + head18
    + fil19 + "nash>" + head19
    + fil20 + "roos>" + head20
    + fil21 + "ridg>" + head21
    + fil22 + "capi>" + head22
    + "</A> <A ID=notbr2 HREF=#help>(help)</A>" + fend);
    }

    Anyone care to show me the more efficient way?
    (It would take me a week to teach myself how to do it.)



    It's taking an extra 5 seconds to show the page with that klunky format - I'm assuming a more efficient method would cut a couple seconds off that.
    Last edited by HTML; 03-20-2007 at 12:54 PM.

  2. #2
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    You could try a switch statement, its basically a shortcut to replace lots of if statements. I would guess its runtime is quicker than successive 'ifs', but have not comapred them.

    here is a sample -

    Code:
    switch(testedVariable)
    {
       case "home" : {contentPage = "home.htm"; break}
       case "programs" : {contentPage = "programs.htm"; break}
       case "membership" : {contentPage = "membership.htm"; break}
       case "notices" : {contentPage = "notices.htm"; break}
       case "minutes" :    {contentPage = "minutes.htm"; break}
       case "links" : {contentPage = "links.htm"; break}
       case "calendar" : {contentPage = "calendar.htm"; break}
       case "newsletter" : {contentPage = "newsletter.htm"; break}
       default : {contentPage = "home.htm"; break}    
    };
    Note: The break is essential. If you miss out the breaks, it will find a match, execute it, then execute the match below it, and the match below that..
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

  3. #3
    Mr. Blue's Avatar
    Evil twin of Dave

    Status
    Offline
    Join Date
    Jul 2001
    Location
    MA, USA
    Posts
    148
    You meant Rube Goldberg right Benz? :P

    -Dave

  4. #4
    benzden's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Feb 2002
    Location
    San Antonio, Texas
    Posts
    652
    Yeah, Goldfarb also sounds better to me for the items in question - Goldberg is just too ordinary a name.

    QuietDean -

    I don't understand how what you've got there will help with a bunch of sub-menu items directed to other parts of the same page -- there being no other web pages involved with any of the <A HREF=#...></A> to a corresponding <A NAME=...></A> type links in my Rube Goldberg script --- unless you're implying by example that I can merely replace each of the name.htm files with the #abbr street names and then figure out how to go from there.

    (I remember the CASE command being used in QuickBasic - didn't use it much, if at all, either.)

    I'll get around to testing that in the next couple days.
    Last edited by benzden; 06-10-2003 at 10:56 AM.

  5. #5
    benzden's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Feb 2002
    Location
    San Antonio, Texas
    Posts
    652
    Okay, here's what works, but it doesn't look like it saves any time: (I did cut out 2 seconds by moving the full names to the doc... write process.)
    Code:
    /*  <SCRIPT LANGUAGE="JavaScript">index('lisb')</SCRIPT>  */
    function index(head) {
    var test=head + " "
    j=test.length
    if (j<=1||test=="undefined "||head=="help") { fend=" " }
     else { fend= "<HR ID=18gr NOSHADE SIZE=1 WIDTH=76%>" }
    var fil0 = "<A ID=notbl1 HREF=#" ;
    var fil1 = " " + fil0 ;
    var fil2 = fil1 ;
    var fil3 = fil1 ;
    var fil4 = fil1 ;
    var fil5 = fil1 ;
    var fil6 = "<BR>" + fil0 ;
    var fil7 = fil1 ;
    var fil8 = fil1 ;
    var fil9 = fil1 ;
    var fil10= fil1 ;
    var fil11= fil1 ;
    var fil12= "<BR>" + fil0 ;
    var fil13= fil1 ;
    var fil14= fil1 ;
    var fil15= fil1 ;
    var fil16= fil1 ;
    var fil17= fil1 ;
    var fil18= "<BR>" + fil0 ;
    var fil19= fil1 ;
    var fil20= fil1 ;
    var fil21= fil1 ;
    var fil22= fil1 ;
    var fill = "<A ID=notrd4 HREF=#" ; var filw = " " + fill ;
    switch(head) {
    case "lisb" : {fil0 = fill         ; break}
    case "spau" : {fil1 = filw         ; break}
    case "garf" : {fil2 = filw         ; break}
    case "nort" : {fil3 = filw         ; break}
    case "mein" : {fil4 = filw         ; break}
    case "wrig" : {fil5 = filw         ; break}
    case "clar" : {fil6 = "<BR>" + fill; break}
    case "cent" : {fil7 = filw         ; break}
    case "hadl" : {fil8 = filw         ; break}
    case "locu" : {fil9 = filw         ; break}
    case "cham" : {fil10= filw         ; break}
    case "burl" : {fil11= filw         ; break}
    case "auer" : {fil12= "<BR>" + fill; break}
    case "bonn" : {fil13= filw         ; break}
    case "sieb" : {fil14= filw         ; break}
    case "conc" : {fil15= filw         ; break}
    case "bern" : {fil16= filw         ; break}
    case "town" : {fil17= filw         ; break}
    case "keef" : {fil18= "<BR>" + fill; break}
    case "nash" : {fil19= filw         ; break}
    case "roos" : {fil20= filw         ; break}
    case "ridg" : {fil21= filw         ; break}
    case "capi" : {fil22= filw         ; break}
    default     : {test = "help"       ; break}
    }
    document.write("<A NAME=" + head + "><P><TT ID=notrd6>[Intersection]</TT><BR>"
    + fil0  + "lisb>Lisbon"
    + fil1  + "spau>Spaulding"
    + fil2  + "garf>Garfield"
    + fil3  + "nort>North"
    + fil4  + "mein>Meinecke"
    + fil5  + "wrig>Wright"
    + fil6  + "clar>Clarke"
    + fil7  + "cent>Center"
    + fil8  + "hadl>Hadley"
    + fil9  + "locu>Locust"
    + fil10 + "cham>Chambers"
    + fil11 + "burl>Burleigh"
    + fil12 + "auer>Auer"
    + fil13 + "bonn>Bonny"
    + fil14 + "sieb>Sieben"
    + fil15 + "conc>Concordia"
    + fil16 + "bern>Bernhard"
    + fil17 + "town>Townsend"
    + fil18 + "keef>Keefe"
    + fil19 + "nash>Nash"
    + fil20 + "roos>Roosevelt"
    + fil21 + "ridg>Ridge"
    + fil22 + "capi>Capitol"
    + "</A> <A ID=notbr2 HREF=#help>(help)</A>" + fend);
    }
    Now I remember CASE better - did use it more often than I'd thought.



Tags for this Thread