Simple problem with function.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • koen colen

    Simple problem with function.

    Hi, simple question I guess. The question is actually in the code itself as
    this was the simplest way to explain.

    ....
    var favorite = GetCookie('lang ');

    if (favorite != null) {
    switch (favorite) {
    case 'nederlands' : url = 'ned.html';
    break;
    case 'english' : url = 'en.html';
    break;
    case 'francais' : url = 'fr.html';
    break;
    case 'deutsch' : url = 'de.html';
    break;
    case 'italiano' : url = 'I dont want you to take another page, continue
    loading this page because this is the italiano page';

    }
    window.location .href = url;
    }
    ....

    Anyone can give me the magic word I'm searching for? I thought it was "self"
    but that didn't do the trick, damn :-). And when I leave it empty then it
    hangs in a loop. I just want to say "when case is Italiano skip "the
    window.location .href" part and continue loading this page.

    Many Thanks!
    --

    Grtz,
    Koen Colen


  • Douglas Crockford

    #2
    Re: Simple problem with function.

    > Hi, simple question I guess. The question is actually in the code itself as[color=blue]
    > this was the simplest way to explain.
    >
    > var favorite = GetCookie('lang ');
    >
    > if (favorite != null) {
    > switch (favorite) {
    > case 'nederlands' : url = 'ned.html';
    > break;
    > case 'english' : url = 'en.html';
    > break;
    > case 'francais' : url = 'fr.html';
    > break;
    > case 'deutsch' : url = 'de.html';
    > break;
    > case 'italiano' : url = 'I dont want you to take another page, continue
    > loading this page because this is the italiano page';
    >
    > }
    > window.location .href = url;
    > }
    > ...
    >
    > Anyone can give me the magic word I'm searching for? I thought it was "self"
    > but that didn't do the trick, damn :-). And when I leave it empty then it
    > hangs in a loop. I just want to say "when case is Italiano skip "the
    > window.location .href" part and continue loading this page.[/color]

    First, the title of the message is wrong. This isn't a function. A function is a
    very specific and useful thing. Call things by their correct names.

    Second, you are using a switch statement to do something better done with an
    object.

    var pages = {nederlands: 'ned.html', english: 'en.html', francais:
    'fr.html', deutsch: 'de.html'};

    function lang_page(lang) {
    var u = pages[lang];
    if (typeof u == 'string') {
    window.location .href = u;
    }
    }



    Comment

    • Michael Winter

      #3
      Re: Simple problem with function.

      On Mon, 19 Jan 2004 21:26:47 GMT, koen colen <koen.colen@pan dora.be> wrote:
      [color=blue]
      > Anyone can give me the magic word I'm searching for? I thought it was
      > "self" but that didn't do the trick, damn :-). And when I leave it
      > empty then it hangs in a loop. I just want to say "when case is
      > Italiano skip "the window.location .href" part and continue loading
      > this page.[/color]

      Simply modify it to:

      function changePage() {
      var favorite = GetCookie('lang ');
      var url = null;

      if (favorite != null) {
      switch (favorite) {
      case 'nederlands':
      url = 'ned.html';
      break;
      case 'english':
      url = 'en.html';
      break;
      case 'francais':
      url = 'fr.html';
      break;
      case 'deutsch':
      url = 'de.html';
      break;
      case 'italiano':
      // no action
      break;
      }
      }
      if (url) window.location .href = url;
      }

      If you're trying to reload the page, you could replace "// no action" with
      "window.locatio n.reload();".

      Hope that helps,
      Mike

      --
      Michael Winter
      M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

      Comment

      • koen colen

        #4
        Re: Simple problem with function.

        That was exactly what I was looking for Mike. Many thanks! Thanks for the
        reply Douglas!

        And I'm meaning it :-)
        Koen


        "Michael Winter" <M.Winter@bluey onder.co.invali d> schreef in bericht
        news:opr11lrcyg 5vklcq@news-text.blueyonder .co.uk...[color=blue]
        > On Mon, 19 Jan 2004 21:26:47 GMT, koen colen <koen.colen@pan dora.be>[/color]
        wrote:[color=blue]
        >[color=green]
        > > Anyone can give me the magic word I'm searching for? I thought it was
        > > "self" but that didn't do the trick, damn :-). And when I leave it
        > > empty then it hangs in a loop. I just want to say "when case is
        > > Italiano skip "the window.location .href" part and continue loading
        > > this page.[/color]
        >
        > Simply modify it to:
        >
        > function changePage() {
        > var favorite = GetCookie('lang ');
        > var url = null;
        >
        > if (favorite != null) {
        > switch (favorite) {
        > case 'nederlands':
        > url = 'ned.html';
        > break;
        > case 'english':
        > url = 'en.html';
        > break;
        > case 'francais':
        > url = 'fr.html';
        > break;
        > case 'deutsch':
        > url = 'de.html';
        > break;
        > case 'italiano':
        > // no action
        > break;
        > }
        > }
        > if (url) window.location .href = url;
        > }
        >
        > If you're trying to reload the page, you could replace "// no action" with
        > "window.locatio n.reload();".
        >
        > Hope that helps,
        > Mike
        >
        > --
        > Michael Winter
        > M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)[/color]


        Comment

        • Evertjan.

          #5
          Re: Simple problem with function.

          koen colen wrote on 19 jan 2004 in comp.lang.javas cript:
          [color=blue]
          > var favorite = GetCookie('lang ');
          >
          > if (favorite != null) {
          > switch (favorite) {
          > case 'nederlands' : url = 'ned.html';
          > break;
          > case 'english' : url = 'en.html';
          > break;
          > case 'francais' : url = 'fr.html';
          > break;
          > case 'deutsch' : url = 'de.html';
          > break;
          > case 'italiano' : url = 'I dont want you to take another page, continue
          > loading this page because this is the italiano page';
          >
          >}
          > window.location .href = url;
          >}
          > ...
          >[/color]

          Ik zou het zo doen:

          var favorite = GetCookie('lang '); // in fact unknown function?
          if (favorite == 'nederlands') location.href=' ned.html';
          if (favorite == 'english') location.href=' en.html';
          if (favorite == 'francais') location.href=' fr.html';
          if (favorite == 'deutsch') location.href=' de.html';
          // 'italiano'


          --
          Evertjan.
          The Netherlands.
          (Please change the x'es to dots in my emailaddress)

          Comment

          • Evertjan.

            #6
            Re: Simple problem with function.

            Michael Winter wrote on 19 jan 2004 in comp.lang.javas cript:
            [color=blue]
            > On Mon, 19 Jan 2004 21:26:47 GMT, koen colen <koen.colen@pan dora.be>
            > wrote:
            >[color=green]
            >> Anyone can give me the magic word I'm searching for? I thought it was
            >> "self" but that didn't do the trick, damn :-). And when I leave it
            >> empty then it hangs in a loop. I just want to say "when case is
            >> Italiano skip "the window.location .href" part and continue loading
            >> this page.[/color]
            >
            > Simply modify it to:
            >
            > function changePage() {
            > var favorite = GetCookie('lang ');
            > var url = null;
            >
            > if (favorite != null) {
            > switch (favorite) {
            > case 'nederlands':
            > url = 'ned.html';
            > break;
            > case 'english':
            > url = 'en.html';
            > break;
            > case 'francais':
            > url = 'fr.html';
            > break;
            > case 'deutsch':
            > url = 'de.html';
            > break;
            > case 'italiano':
            > // no action
            > break;
            > }
            > }
            > if (url) window.location .href = url;
            > }
            >
            > If you're trying to reload the page, you could replace "// no action"
            > with "window.locatio n.reload();".[/color]

            Then it would reload forever !


            --
            Evertjan.
            The Netherlands.
            (Please change the x'es to dots in my emailaddress)

            Comment

            • Michael Winter

              #7
              Re: Simple problem with function.

              On 20 Jan 2004 00:28:53 GMT, Evertjan. <exjxw.hannivoo rt@interxnl.net >
              wrote:
              [color=blue][color=green]
              >> If you're trying to reload the page, you could replace "// no action"
              >> with "window.locatio n.reload();".[/color]
              >
              > Then it would reload forever ![/color]

              That's an incredibly good point.

              I've e-mailed the OP to apprise him of that absurdly stupid error. Thank
              you so much, Evertjan, for saying that.

              Mike

              --
              Michael Winter
              M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

              Comment

              Working...