How to specify the selected item by default?

    2 answers 2

    <option id="d" selected/> 

    UPD1:
    Or

     <head> <script> function init(){ document.getElementById('qwe').checked = true; } </script> </head> <body onload="init()"> <input type="checkbox" id="qwe" /> </body> 

    UPD2 :

     function status($value) { $res=mysql_query("SELECT status_name FROM status"); echo "<select name="status">"; while($row=mysql_fetch_assoc($res)) { $flag = 1; foreach($row as $a){ if ($flag == 1){ echo "<option value=".$a." selected>".$a."</option>"; $flag=0; } else echo "<option value=".$a.">".$a."</option>";} } echo "</select>"; } 

    Something like that. If in a hurry.

    • Here's how to make $ value selected as select? function status ($ value) {$ res = mysql_query ("SELECT status_name FROM status "); echo "<select name = 'status'>"; while ($ row = mysql_fetch_assoc ($ res)) {foreach ($ row as $ a) {echo "<option value =". $ a. ">". $ a. "</ option>"; }} echo "</ select>"; } - nail_gizatullin
    • What kind of checker is he if he is selected? - knes
    • @knes, everything is fine! I checked. The property for input type = "checkbox" is checked. - Anton Mukhin
    • This is how it is possible: <input type = "checkbox" id = "qw1e" checked /> - Anton Mukhin
    • @ Anton Mukhin, did you read the question? O_o <br> And then the checkbox? - Zowie

    If I understand correctly, it should be so

     <select name="имя"> <option disabled>Выберите пункт</option> //Заблокированный, если нужен <option value="пункт1">пункт1</option> <option selected="selected" value="пункт2">пункт2</option>//Пункт поумолчанию <option value="пункт3">пункт3</option> атрибутом "selected " <option value="пункт4">пункт4</option> </select>