Page 1 of 1
help making picklist auto pick ?? Please
Posted: Tue Jan 07, 2003 4:01 pm
by rponchek
I am trying to make a picklist automatically pick a user selected option, without hitting a "go" or submit button.
Can this be done with PHP, if not, I hear it can with Java... How do you do this, please help...
Posted: Tue Jan 07, 2003 5:11 pm
by Elmseeker
I don't think you can use PHP for this, Javascript can do it but I don't know any JScript so I don't know how.
Posted: Wed Jan 08, 2003 8:14 am
by Rob the R
Elmseeker is right - Javascript is the way to do this. The way I do it is to utilize the "onChange" method of the picklist (a "select" object in HTML forms parlance) to call a Javascript function that will do what I want right then. The example below loads a new page based on what the user selects from the list.
Code: Select all
<html>
<head>
<script language="Javascript">
<!--
function gotoPage() {
if (document.selectpage.pagelist.value != "") {
if (top.main && top.main.document) {
top.main.document.location.href =
document.selectpage.pagelist.value + ".html" ;
}
else {
document.location.href =
document.selectpage.pagelist.value + ".html" ;
}
}
}
// -->
</script>
</head>
<body>
<form name="selectpage">
<select name="pagelist" onChange="gotoPage();">
<option value="" disabled>Select from this list</option>
<option value="page1">First Page</option>
<option value="page2">Second Page</option>
<option value="page3">Third Page</option>
</select>
</form>
</body>
</html>