Home >Backend Development >PHP Tutorial >How to pass value in php page
PHP page value transfer
Does not use a form to transfer the value of the drop-down box. In fact, it is very simple and can be achieved by using js to obtain it. See the code below
<script type="text/javascript"> function getsel(){ var obj = document.getElementById("sel").value; if(obj== ""){ obj = "0"; } var newhref = "b.php?obj="+obj; var ona = document.getElementById('ona'); ona.href = newhref; } </script> <select id="sel"> <?php foreach ($sql_res as $value) { ?> <option value="<?php echo $value[belongs];?>"><?php echo $value[belongs];?></option> <?php };?> </select> <a id='ona' href="" target="_blank" onclick="getsel()">传值</a>
It can be achieved by assigning a value to the href of the a tag at the click time
In b. php just needs to get the parameters
<?php $obj = $_REQUEST['obj']; echo $obj; ?>