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
  1. #1
    New Coder
    Join Date
    Mar 2005
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Multiple actions for single drop down menu

    I want to build a single drop down menu that will execute a different action dependent on the option selected.

    Here is what I have. We have numerical indicators for pieces of equipment. I have three types of equipment. I currently have three separate drop down menus. I have it set that way because the action in the form is pointed to a certain file. Here is my current code:
    Code:
    <form method="POST" action="file1.php">
    <SELECT name="site" onChange="form.submit()">
    <option></option>
    --------------------------------
    <form method="POST" action="file2.php">
    <SELECT name="site" onChange="form.submit()">
    <option></option>
    --------------------
    <form method="POST" action="file3.php">
    <SELECT name="site" onChange="form.submit()">
    <option></option>
    I want to combine these three into one drop down menu because the options are all numbers. But only certain numbers can go to certain php file because I have three different tables in my database. Also the three different php files display different information.

    Here is another way to explain it:
    options 1-5 goes to action="file1.php"
    options 6-10 and 20 goes to action="file2.php"
    options 11, 15, and 34 goes to action="file3.php"
    All in one single drop down menu.

    I am not sure this is even possible. Also I don't know javascript.
    Thanks in advance.

  • #2
    New to the CF scene
    Join Date
    May 2005
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    try this:

    <form name="form" method="post">
    <select onChange="JavaScript:check(this.form)" name="opt">
    <option value="file1.php">1</option>
    <option value="file1.php">2</option>
    <option value="file2.php">3</option>
    <option value="file2.php">4</option>
    <option value="file3.php">5</option>
    <option value="file3.php">6</option>
    </select>
    </form>

    <script language="JavaScript">
    function check() {
    var number = document.form.opt.selectedIndex;
    location.href = document.form.opt.options[number].value;
    }
    </script>

    you can add as many options as you want without changing the script, just make sure that your option has the value of the file name that you want to go to.

    matt

  • #3
    New Coder
    Join Date
    Mar 2005
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Matt,
    Thanks for your post. It is close but still fails. It goes to the correct php but does not pass the numeric value. I changed the variables on each php page to match the name "opt" The number are not in order, I say this because I am curious about the selectedIndex part of the JS.

    Here is the code I have put in.
    <form name="form" method="post">
    <select onChange="JavaScript:check(this.form)" name="opt">
    <option value="siteinfotemplate1.php">1</option>
    <option value="siteinfotemplate1.php">2</option>
    <option value="siteinfotemplate1.php">3</option>
    <option value="siteinfotemplate1.php">7</option>
    <option value="ngsinfotemplate1.php">300</option>
    <option value="ngsinfotemplate1.php">305</option>
    </select>
    </form>

    <script language="JavaScript">
    function check() {
    var number = document.form.opt.selectedIndex;
    location.href = document.form.opt.options[number].value;
    }
    </script>


    The change made on the php pages: (ngsinfotemplate1.php and siteinfotemplate1.php)
    $tnumber = $_POST['opt'];

    If you look at the last option, I need the number 305 to post to ngsinfotemplate1.php.


    Thanks a lot for taking some time to look at this.
    Frank


  •  

    Posting Permissions

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