• Lucid Dreaming - Dream Views




    Results 1 to 6 of 6
    1. #1
      Christian youssarian's Avatar
      Join Date
      Dec 2007
      Gender
      Location
      Independence, Kansas
      Posts
      441
      Likes
      41

      HTML/JavaScript Help: Option Boxes

      I've been tearing my hair out to try and get this working. I'm trying to make a select menu which, when an element is selected and the submit button pressed, it does a function. This is a simplified version of the code:

      <html>
      <head>
      <script type="text/javascript">
      function blah()
      {
      if (document.form.select.one.selected)
      { alert("Hello")
      }
      if (document.form.select.two.selected)
      { alert("Goodbye")
      }
      }
      </script>
      </head>
      <body>
      <form name="form" onsubmit="blah()">
      <select name="select">
      <option name="one" value="one">One</option>
      <option name="two" value="two">Two</option>
      <option name="three" value="three">Three</option>
      </select>
      <input type="submit" name="click" value="Go!"></input>
      </form>
      </body>
      </html>


      Please help me. I don't know where to go with this. I've already tried several variations but none worked.
      Learn the art of lucid dreaming in a whole new way!
      LD Count: 37 (35 DILD, 2 DEILD)

      Hey Newbies! Did you read the main pages and the tutorials? It will help you immensely.

      Zenventive: art, health, philosophy
      You are dreaming!

    2. #2
      FBI agent Ynot's Avatar
      Join Date
      Oct 2005
      Gender
      Location
      Southend, Essex
      Posts
      4,337
      Likes
      14
      Code:
      <html>
      <head>
      <script type="text/javascript">
      function blah()
      {
      if (document.getElementById('opt_one').selected)
      { alert("Hello");
      }
      if (document.getElementById('opt_two').selected)
      { alert("Goodbye");
      }
      }
      </script>
      </head>
      <body>
      <form name="form" id="form" onsubmit="blah(); return false">
      <select name="select">
      <option name="one" id="opt_one" value="one">One</option>
      <option name="two" id="opt_two" value="two">Two</option>
      <option name="three" id="opt_three" value="three">Three</option>
      </select>
      <input type="submit" name="click" value="Go!"></input>
      </form>
      </body>
      </html>
      Last edited by Ynot; 06-17-2008 at 07:01 PM.

    3. #3
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      935
      Ynot's is better code, but there is a GetElementByName() function as well.

      Code:
      if (document.getElementByName('one').selected)
      But you should use ids, it's just better programming.

    4. #4
      Christian youssarian's Avatar
      Join Date
      Dec 2007
      Gender
      Location
      Independence, Kansas
      Posts
      441
      Likes
      41
      Much thanks to you guys.
      Learn the art of lucid dreaming in a whole new way!
      LD Count: 37 (35 DILD, 2 DEILD)

      Hey Newbies! Did you read the main pages and the tutorials? It will help you immensely.

      Zenventive: art, health, philosophy
      You are dreaming!

    5. #5
      What's up <span class='glow_006400'>[SomeGuy]</span>'s Avatar
      Join Date
      Nov 2007
      LD Count
      About 1
      Gender
      Location
      Tmux on Debian
      Posts
      2,862
      Likes
      130
      DJ Entries
      4
      Code:
      <html>
      <head>
      <script type="text/javascript">
      function blah(){
          if (document.form.(select_one).selected)
          { 
          alert("Hello")
          }
          if (document.form.(select_two).selected)
          { 
          alert("Goodbye")
          }
      }
      </script>
      </head>
      <body>
      <form name="form" onSubmit="blah()">
       <select name="select">
         <option name="one" value="one">One</option>
         <option name="two" value="two">Two</option>
         <option name="three" value="three">Three</option>
       </select>
      <input type="submit" id="click" value="Go!"></input>
      </form>
      </body>
      </html>

      Hey guys, I'm back. Feels good man
      ---------------------------------------------------
      WTF|Jesus lul
      spam removed

    6. #6
      FBI agent Ynot's Avatar
      Join Date
      Oct 2005
      Gender
      Location
      Southend, Essex
      Posts
      4,337
      Likes
      14
      use getElementById

      it's safest,
      anything else may not be portable across different browsers

    Bookmarks

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •