Jump to content

[SOLVED] DropDown Select


Minase

Recommended Posts

hy there i do have a dropdown

<select name="test" size=1>
<option value="2">123</option>
<option value="3">test</option>
<option value="4">something</option>

 

and a variable $a.

i want if variable $a == 4 then the dropdown box to have the selected input 4.

 

and another problem

if $b = "abcd";

i want to search in this variable for values like

if $b has "a" than $a1 = 1;

 

hope you understand

thanks

Link to comment
https://forums.phpfreaks.com/topic/121113-solved-dropdown-select/
Share on other sites

Yes i did understand you, i have shown you how to make something selected, i am not writing it all for you. Please try your self.

 

All you need to do is add an if statment.

 

There are two ways ,

first:

<option selected="selected" value="<?php if($a == 4) echo 4; ?>"><?php if($a == 4) echo 4; ?></option>

second:

<option value="2" <?php if($a == 2) echo "selected='selected'";?>>123</option>

<option value="3" <?php if($a == 3) echo "selected='selected'";?>>test</option>

<option value="4" <?php if($a == 4) echo "selected='selected'";?>>something</option>

 

maybe someone have a better ideea how to do this .let me explain:

 

i do have a variable $access

$access = "1234567";

and 7 checkboxes with name from 1-7 i want if the variable contain 134 the checkboxes with name 1,3,4 to be checked.

but i cant figure out what is the best method

i was thinking to split those numbers and use an if statement,but i cant make it to split so anyone has ideeas?

thanks

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.