php_begins Posted September 28, 2011 Share Posted September 28, 2011 I have a drop down list which retrieves site name acronym and the url from the database. I need help in 2 things. 1.I do not want the url to be displayed in the drop down list. 2. When I hit submit I need to echo the sitename acronym as well as the url in a page called display.php. Here is my code so far: <form action="display.php" method ="post"> <tr> <td>Category</td> <td> <select name="new_id"> <option value="">=============</option> <?php foreach($acronym as $key=>$value){ ?> <option value="<?php echo $value['site_id']; ?>"><?php echo $value['acronym']; ?></option> <option value="<?php echo $value['site_id']; ?>"><?php echo $value['url']; ?></option> <?php }?> </td> </tr> <input type="submit" name="submit" value="submit" /> </form> Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted September 28, 2011 Share Posted September 28, 2011 If you don't want the URL to show in the list, don't echo it in <option></option> tags. Use the site_id value from the $_POST array to query the database and retrieve the information you want displayed on the page after the form is submitted. Quote Link to comment Share on other sites More sharing options...
php_begins Posted September 28, 2011 Author Share Posted September 28, 2011 is there any other alternative. I do not want to query the database on display.php Quote Link to comment Share on other sites More sharing options...
php_begins Posted September 28, 2011 Author Share Posted September 28, 2011 maybe a hidden field or somethin? Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted September 28, 2011 Share Posted September 28, 2011 Why not? It would be the sensible way to do it. Quote Link to comment Share on other sites More sharing options...
xyph Posted September 29, 2011 Share Posted September 29, 2011 Use JavaScript. <?php $acronym = array( array( 'site_id' => '1', 'acronym' => 'HelloWorld', 'url' => 'http://www.helloworld.com/' ), array( 'site_id' => '2', 'acronym' => 'FooBar', 'url' => 'http://www.foobar.com/' ), array( 'site_id' => '3', 'acronym' => 'HerpDerp', 'url' => 'http://www.herpderp.com/' ) ); if( $_POST ) { echo '<pre>'; print_r($_POST); echo '</pre>'; } ?> <script type="text/javascript"> function doSubmit() { var form = document.getElementById('thisForm'); var select = document.getElementById('thisFormSelect'); var acronym = { <?php $comma = FALSE; foreach ( $acronym as $o ) { echo ($comma ? ',':'') . "'{$o['site_id']}':{'acronym':'{$o['acronym']}','url':'{$o['url']}'}"; $comma = TRUE; } ?> }; if( select.value in acronym ) { var url = document.createElement( 'input' ); url.name = 'url'; url.type = 'hidden'; url.value = acronym[ select.value ]['url']; var acro = document.createElement( 'input' ); acro.name = 'name'; acro.type = 'hidden'; acro.value = acronym[ select.value ]['acronym']; form.appendChild( url ); form.appendChild( acro ); form.submit(); } } </script> <form id="thisForm" action="#" method="post"> <div id="boobies"> Category: <select id="thisFormSelect" name="id"> <?php foreach( $acronym as $option ) echo '<option value="'.$option['site_id'].'">'.$option['acronym'].'</option>'; ?> </select><br> <input type="button" value="Submit" onclick="doSubmit()"> </div> </form> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.