helpmescript
helpmescript

Reputation: 29

How do I make this to a php string and echo it into <select>?

This makes me crazy I cant get it to work.

This is what ive done:

$v = "<?php if($test== 'lala' || $test== 'kaka'){echo selected='selected';}?>";
$b = "<?php if($test== 'tada' || $test== 'sada'){echo selected='selected';}?>";

<select>
      <option <?php echo $v; ?> value="lala">lala</option>
        <option  <?php echo $b; ?> value="tada">tada</option>
</select>

in the dropdown this gives me: value="tada">tada and it should only be tada

Upvotes: 2

Views: 47

Answers (1)

Shad Mickelberry
Shad Mickelberry

Reputation: 291

Your quotes are messed up.

Change:

    $v = "<?php if($test== 'lala' || $test== 'kaka'){echo selected='selected';}?>";
$b = "<?php if($test== 'tada' || $test== 'sada'){echo selected='selected';}?>";

To:

<option <?php if($test== 'lala' || $test== 'kaka'){echo 'selected=selected';}?> value="lala">lala</option>
<option  <?php if($test== 'tada' || $test== 'sada'){echo 'selected=selected';} ?> value="tada">tada</option>

Upvotes: 1

Related Questions