Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. JavaScript Conditional

JavaScript Conditional

Scheduled Pinned Locked Moved The Weird and The Wonderful
javascriptquestiondiscussion
13 Posts 11 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Andres Martin

    Hi, this is my post! :S

    function GoPage(accion)
    {
    if(accion == "G")
    window.location.href = 'resultadointerfaz.asp?vyear='+ document.getElementById('Select2').value+'&vmes='+document.getElementById('Select1').value+'&tipo='+document.getElementById('tipo').value+'&consultar=G';
    else
    window.location.href = 'resultadointerfaz.asp?vyear='+ document.getElementById('Select2').value+'&vmes='+document.getElementById('Select1').value+'&tipo='+document.getElementById('tipo').value+'&consultar=C';
    }

    What do you think. I think that the else is not necesary! bye!

    L Offline
    L Offline
    Luc Pattyn
    wrote on last edited by
    #2

    there is a 1-letter difference near the end! :)

    Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

    Please use < PRE > tags for code snippets, it preserves indentation, and improves readability.

    modified on Wednesday, June 23, 2010 7:41 PM

    O K 2 Replies Last reply
    0
    • L Luc Pattyn

      there is a 1-letter difference near the end! :)

      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

      Please use < PRE > tags for code snippets, it preserves indentation, and improves readability.

      modified on Wednesday, June 23, 2010 7:41 PM

      O Offline
      O Offline
      oggenok64
      wrote on last edited by
      #3

      Good spotting. I missed that.

      1 Reply Last reply
      0
      • L Luc Pattyn

        there is a 1-letter difference near the end! :)

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

        Please use < PRE > tags for code snippets, it preserves indentation, and improves readability.

        modified on Wednesday, June 23, 2010 7:41 PM

        K Offline
        K Offline
        Kevin Drzycimski
        wrote on last edited by
        #4

        yes there is =D but the whole function could be written better, with regard to DRY

        1 Reply Last reply
        0
        • A Andres Martin

          Hi, this is my post! :S

          function GoPage(accion)
          {
          if(accion == "G")
          window.location.href = 'resultadointerfaz.asp?vyear='+ document.getElementById('Select2').value+'&vmes='+document.getElementById('Select1').value+'&tipo='+document.getElementById('tipo').value+'&consultar=G';
          else
          window.location.href = 'resultadointerfaz.asp?vyear='+ document.getElementById('Select2').value+'&vmes='+document.getElementById('Select1').value+'&tipo='+document.getElementById('tipo').value+'&consultar=C';
          }

          What do you think. I think that the else is not necesary! bye!

          V Offline
          V Offline
          Viorel
          wrote on last edited by
          #5

          Since setting of href does not necessary stop the scripts and jump to new address, I think that else is required. But the code can be probably replaced with a single line like this:

          window.location.href = "...&consultar=" + accion;

          E 1 Reply Last reply
          0
          • A Andres Martin

            Hi, this is my post! :S

            function GoPage(accion)
            {
            if(accion == "G")
            window.location.href = 'resultadointerfaz.asp?vyear='+ document.getElementById('Select2').value+'&vmes='+document.getElementById('Select1').value+'&tipo='+document.getElementById('tipo').value+'&consultar=G';
            else
            window.location.href = 'resultadointerfaz.asp?vyear='+ document.getElementById('Select2').value+'&vmes='+document.getElementById('Select1').value+'&tipo='+document.getElementById('tipo').value+'&consultar=C';
            }

            What do you think. I think that the else is not necesary! bye!

            J Offline
            J Offline
            Jeroen De Dauw
            wrote on last edited by
            #6

            Obviously a genetic algorithm should be used to evolve the URL, why can't some programmers figure that out? >_>

            Jeroen De Dauw
            Blog ; Wiki

            1 Reply Last reply
            0
            • A Andres Martin

              Hi, this is my post! :S

              function GoPage(accion)
              {
              if(accion == "G")
              window.location.href = 'resultadointerfaz.asp?vyear='+ document.getElementById('Select2').value+'&vmes='+document.getElementById('Select1').value+'&tipo='+document.getElementById('tipo').value+'&consultar=G';
              else
              window.location.href = 'resultadointerfaz.asp?vyear='+ document.getElementById('Select2').value+'&vmes='+document.getElementById('Select1').value+'&tipo='+document.getElementById('tipo').value+'&consultar=C';
              }

              What do you think. I think that the else is not necesary! bye!

              T Offline
              T Offline
              Tsuda Kageyu
              wrote on last edited by
              #7

              We love copy and paste.

              1 Reply Last reply
              0
              • A Andres Martin

                Hi, this is my post! :S

                function GoPage(accion)
                {
                if(accion == "G")
                window.location.href = 'resultadointerfaz.asp?vyear='+ document.getElementById('Select2').value+'&vmes='+document.getElementById('Select1').value+'&tipo='+document.getElementById('tipo').value+'&consultar=G';
                else
                window.location.href = 'resultadointerfaz.asp?vyear='+ document.getElementById('Select2').value+'&vmes='+document.getElementById('Select1').value+'&tipo='+document.getElementById('tipo').value+'&consultar=C';
                }

                What do you think. I think that the else is not necesary! bye!

                W Offline
                W Offline
                whatrevolution
                wrote on last edited by
                #8

                I think: function GoPage(accion) { if (accion == "G") { consultar_val = G; } else { consultar_val = C; } window.location.href = 'resultadointerfaz.asp?vyear='+document.getElementById('Select2').value+'&amp;vmes='+document.getElementById('Select1').value+'&amp;tipo='+document.getElementById('tipo').value+'&amp;consultar='+consultar_val; }

                Honestly Illustrated

                <Pretentious> Raid tha manyuhl. :E <Pretentious> Aw raid eh own mah meaxbile. :E

                L J 2 Replies Last reply
                0
                • W whatrevolution

                  I think: function GoPage(accion) { if (accion == "G") { consultar_val = G; } else { consultar_val = C; } window.location.href = 'resultadointerfaz.asp?vyear='+document.getElementById('Select2').value+'&amp;vmes='+document.getElementById('Select1').value+'&amp;tipo='+document.getElementById('tipo').value+'&amp;consultar='+consultar_val; }

                  Honestly Illustrated

                  <Pretentious> Raid tha manyuhl. :E <Pretentious> Aw raid eh own mah meaxbile. :E

                  L Offline
                  L Offline
                  Lutoslaw
                  wrote on last edited by
                  #9

                  Controls' names Select1 and Select2 are another horror.

                  Greetings - Jacek

                  W 1 Reply Last reply
                  0
                  • L Lutoslaw

                    Controls' names Select1 and Select2 are another horror.

                    Greetings - Jacek

                    W Offline
                    W Offline
                    whatrevolution
                    wrote on last edited by
                    #10

                    <select id="Select4"><option>Bad Idea></option></select> <select id="Select2"><option>Bad idea></option></select> <select id="Select7"><option>bad Idea></option></select> <select id="Select5"><option>bad idea></option></select> <select id="Select1"><option>BadIdea></option></select> <select id="Select6"><option>badIdea></option></select> <select id="Select3"><option>Bad_Idea></option></select> <select id="Select8"><option>bad_idea></option></select>

                    Honestly Illustrated

                    <Pretentious> Raid tha manyuhl. :E <Pretentious> Aw raid eh own mah meaxbile. :E

                    1 Reply Last reply
                    0
                    • V Viorel

                      Since setting of href does not necessary stop the scripts and jump to new address, I think that else is required. But the code can be probably replaced with a single line like this:

                      window.location.href = "...&consultar=" + accion;

                      E Offline
                      E Offline
                      Electron Shepherd
                      wrote on last edited by
                      #11

                      If action is, for example, 'X', your function works differently to the original

                      Server and Network Monitoring

                      1 Reply Last reply
                      0
                      • W whatrevolution

                        I think: function GoPage(accion) { if (accion == "G") { consultar_val = G; } else { consultar_val = C; } window.location.href = 'resultadointerfaz.asp?vyear='+document.getElementById('Select2').value+'&amp;vmes='+document.getElementById('Select1').value+'&amp;tipo='+document.getElementById('tipo').value+'&amp;consultar='+consultar_val; }

                        Honestly Illustrated

                        <Pretentious> Raid tha manyuhl. :E <Pretentious> Aw raid eh own mah meaxbile. :E

                        J Offline
                        J Offline
                        jsc42
                        wrote on last edited by
                        #12

                        Or, simpler:

                        function GoPage(accion)
                        {
                        window.location.href =
                        'resultadointerfaz.asp?vyear=' +
                        document.getElementById('Select2').value +
                        '&vmes=' +
                        document.getElementById('Select1').value +
                        '&tipo=' +
                        document.getElementById('tipo').value +
                        '&consultar=' +
                        (accion == 'G' ? 'G' : 'C');
                        }

                        W 1 Reply Last reply
                        0
                        • J jsc42

                          Or, simpler:

                          function GoPage(accion)
                          {
                          window.location.href =
                          'resultadointerfaz.asp?vyear=' +
                          document.getElementById('Select2').value +
                          '&vmes=' +
                          document.getElementById('Select1').value +
                          '&tipo=' +
                          document.getElementById('tipo').value +
                          '&consultar=' +
                          (accion == 'G' ? 'G' : 'C');
                          }

                          W Offline
                          W Offline
                          whatrevolution
                          wrote on last edited by
                          #13

                          I wanted to use the ternary operator there, too; then I thought of the future case of adding a third "accion" and decided to leave an obvious ability to add an "else if" condition at the top.

                          Honestly Illustrated

                          <Pretentious> Raid tha manyuhl. :E <Pretentious> Aw raid eh own mah meaxbile. :E

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups