#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Posts
    26
    Rep Power
    0
    I have a select form on a page, and I want it to automatically submit when something is selected. How can I do this without having a submit button (or any button)? I'm working with PHP.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2000
    Location
    Englewood, CO
    Posts
    30
    Rep Power
    15
    Use javascript.

    Here:
    <HTML>
    <HEAD>
    <TITLE>Javascript Auto-Navigate On Select</TITLE>
    <SCRIPT LANGUAGE="javascript">
    function ChangeCatcher() {
    if (whatever.myselector.value == 1) {
    window.location = "http://www.hotlinecentral.com";
    } else if (whatever.myselector.value == 2) {
    window.location = "http://www.hotlinecentral.com/hlsearch.shtml";
    } else {
    window.location = "http://www.hotlinecentral.com/links.shtml";
    }
    }
    </SCRIPT>
    </HEAD>
    <BODY>
    <FORM name="whatever">
    <B>Select a place to go: </B>
    <SELECT name="myselector" onchange="ChangeCatcher()">
    <OPTION value="0" SELECTED>- Make a Selection -
    <OPTION value="1">Hotline Central
    <OPTION value="2">Hotline Search
    <OPTION value="3">Hotline Links
    </SELECT>
    </BODY>
    </HTML>


    Oops. You want the form to submit. Instead of using window.location = "",
    use whatever.submit (formname.submit).

    Hope that helps...

    -TM


    [This message has been edited by TroutMask (edited March 01, 2000).]
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Posts
    26
    Rep Power
    0
    Will this work since I am dynamically building the select form with PHP?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2000
    Location
    Englewood, CO
    Posts
    30
    Rep Power
    15
    Yes. You can either embed your PHP code within the HTML or have PHP print out the HTML as I've shown. Remember, PHP is a server-side scripting language while javascript is (primarily) a client-side scripting language.

    What this means in this context is that we can have PHP on the server write anything to the browser. The browser then interprets this. So, if we have PHP send javascript to the browser, the browser will interpret the javascript (as it does the HTML) and act accordingly.

    With the solution as I've provided, there is no need for PHP unless you've got some additional processing required for something else. This will work in a plain .html file.

    -TM

Similar Threads

  1. select across multiple tables (UNION)
    By vickistanfield in forum MySQL Help
    Replies: 3
    Last Post: September 26th, 2003, 08:05 PM
  2. SELECT something FROM (SELECT something2 FROM ...) ...
    By loudo in forum Firebird SQL Development
    Replies: 3
    Last Post: August 21st, 2003, 04:27 AM
  3. creating a select dynamically (search functions)
    By Maarten Martens in forum MySQL Help
    Replies: 1
    Last Post: July 23rd, 2003, 07:52 AM
  4. Dynamic value of select box based on other select box
    By etherwolf in forum HTML Programming
    Replies: 6
    Last Post: October 16th, 2001, 10:11 AM
  5. select box changes other select box...
    By etherwolf in forum PHP Development
    Replies: 6
    Last Post: October 11th, 2001, 11:29 AM

IMN logo majestic logo threadwatch logo seochat tools logo