0

i have this code:

<select class='okin' name='netiotitmn' id='netiotitmi' disabled>
                                    <option> </option>
                                    <?php
                                        $x = 0; $y = 60;
                                        while($x <= $y) {
                                            $selected="";
                                            if ($x=9)      {$selected="selected";}
                                            echo "<option value='$x'  $selected>" . szpad($x) . "</option>";
                                            $x++;
                                        }
                                    ?>
                                </select>

I want set value 9 as a default but it not change everything. Supposedly the value 09 because i set it as default value if open this form and can change the value if the user select another value but it should 9 by default. it just blank and have drop down loop.

2 Answers2

1

Please try with this code :

if ($x == 9)      { $selected = " selected"; }

I changed the following code :

  1. $x == 9 instead of $x = 9
  2. { $selected = " selected"; } instead of { $selected = "selected"; }

It has space :

"selected" => " selected"

And then please replace the following code :

echo "<option value='9'".$selected.">" . szpad($x) . "</option>";
0

You should never set a variable inside an if clause. If you want to check if $x equals 9, then you have to use:

if($x == 9) { ... }

If you want to set all select options to 9, then you could do that in this part of your code:

echo "<option value='9'  $selected>" . szpad($x) . "</option>";
Geshode
  • 3,600
  • 6
  • 18
  • 32
  • I want to make like this example https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_option_selected. But i cant apply it to this coding. The different is it default show audi but mine is 09 . – Fatin Nuratiqa Oct 29 '18 at 07:48