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
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>

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

<?php
if ($a  == (4)){
$a = "selected";
}else{
$a = "";
}
?>

<select name="test" size=1>
<option  value="2">123</option>
<option value="3">test</option>
<option <?php echo $a; ?> value="4">something</option>
</select>

 

 

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.