March 1st, 2000, 09:43 AM
-
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.
March 1st, 2000, 10:24 AM
-
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).]
March 1st, 2000, 10:41 AM
-
Will this work since I am dynamically building the select form with PHP?
March 1st, 2000, 03:16 PM
-
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