Jump to content

drop down list display help


php_begins

Recommended Posts

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>

 

 

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.