php select page change

Solutions on MaxInterview for php select page change by the best coders in the world

showing results for - "php select page change"
Josefa
08 Sep 2018
1<select name="page" onchange="window.location=this.value">
2    <option value="/path/to/page1.php">Page 1</option>
3    <option value="/path/to/page2.php">Page 2</option>
4    <option value="/path/to/page3.php">Page 3</option>
5</select>
6
Etan
11 Mar 2018
1<?php
2$page = null;
3if(isset($_POST['page'])){
4    $page = $_POST['page'];
5}
6switch($page){
7    case 'page3': include_once('/path/to/page3content.php'); break;
8    case 'page2': include_once('/path/to/page2content.php'); break;
9    case 'page1': include_once('/path/to/page1content.php'); break;
10    default: include_once('/path/to/defaultcontent.php'); break;
11}
12?>
13<form name="myform" action="" method="post">
14    <select name="page" onchange="this.form.submit()">
15        <option value="page1"<?php if($page == "page1"){ echo " selected"; }?>>Page 1</option>
16        <option value="page2"<?php if($page == "page2"){ echo " selected"; }?>>Page 2</option>
17        <option value="page3"<?php if($page == "page3"){ echo " selected"; }?>>Page 3</option>
18    </select>
19</form>
20