Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: select

  1. #1
    New Coder
    Join Date
    Sep 2005
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question select

    My form has some select options, is it possible to automaticly submit the page when an option has been selected ? (so that i can get rid of the submit button). It would be great if the code works on any browser.

    <html>
    <head>
    <title>Untitled</title>
    </head>
    <body>
    <form action="www.blablabla.com/cgi-bin/blabla.cgi">

    <select name="area">
    <OPTION value="None">select a City</OPTION>
    <OPTION value="1">London</option>
    <OPTION value="2">Paris</OPTION>
    <OPTION value="3">New York</OPTION>
    </select>

    <input type="submit">
    </form>
    </body>
    </html>

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Sure.

    <select name="area"
    onchange="if (this.selectedIndex != 0) this.form.submit();">

    Oh, note that this means you're throwing accessibility out the window.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,074
    Thanks
    0
    Thanked 256 Times in 252 Posts
    What you can do is hide the submit button onload.
    Code:
    <html>
    <head>
    <title>Untitled</title>
    <script type="text/javascript">
    function init(){
      document.getElementById("btnGo").style.display = "none"; //hide submit button
    }
    </script>
    </head>
    <body onload="init();">
    <form action="www.blablabla.com/cgi-bin/blabla.cgi">
    <select name="area" onchange="if (this.selectedIndex != 0) this.form.submit();">
    <OPTION value="None">select a City</OPTION>
    <OPTION value="1">London</option>
    <OPTION value="2">Paris</OPTION>
    <OPTION value="3">New York</OPTION>
    </select>
    <input type="submit" name="btnGo" id="btnGo" value="Go" />
    </form>
    </body>
    </html>
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

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