selectboxの最近のブログ記事

シンプルなの見つけました。参考にさせていただいたサイト様ありがとうございます。

URL不明になってしまいました^^;。

実践的なコードを載せます。

 

<td>

            <?php

                 $sql = "SELECT * from lotnumber";

                 $result = executeQuery($sql);

                 while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){

                 @$Selectbox .= "<option value=\"".$row["lotnumber"]."\">"."".$row["lotnumber"]."</option>";

                 }

             ?>

            <select style="width:120px; clip:rect(0px,120px,22px,100px); position:absolute;" onchange="select(this);">

            <?= $Selectbox ?>

            </select>

            <input id="t1" name="mlot" type="text" style="width:100px;margin-right:20px;" value=<?= $prefMlot ?>>

            <script language="javascript">

               function select(obj){

               document.getElementById("t1").value=obj.options[obj.selectedIndex].text;

               }

            </script>

</td>

複数の場合は、(自分はちょっとはまりました^^;)

<td>
          <?php
                 $sql = "SELECT * from salesratio";
                 $result = executeQuery($sql);
                 while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
                 @$Selectbox .= "<option value=\"".$row["customer"]."\">"."".$row["customer"]."</option>";
                 }
           ?>
            <select style="width:120px; clip:rect(0px,120px,22px,100px); position:absolute;" onchange="select(this);">
            <?= $Selectbox ?>
            </select>
            <input id="t1" name="customer" type="text" style="width:100px;margin-right:20px;" value=''>
            <script language="javascript">
               function select(obj){
               document.getElementById("t1").value=obj.options[obj.selectedIndex].text;
               }
            </script>
     </td>
     <td>
          <?php
                 $sqla = "SELECT * from salesratio";
                 $resulta = executeQuery($sqla);
                 while ($rowa = mysql_fetch_array($resulta, MYSQL_ASSOC)){
                 @$Selectboxa .= "<option value=\"".$rowa["classification"]."\">"."".$rowa["classification"]."</option>";
                 }
           ?>
            <select style="width:120px; clip:rect(0px,120px,22px,100px); position:absolute;" onchange="selc(this);">
            <?= $Selectboxa ?>
            </select>
            <input id="t2" name="classification" type="text" style="width:100px;margin-right:20px;" value=''>
            <script language="javascript">
               function selc(obj){
               document.getElementById("t2").value=obj.options[obj.selectedIndex].text;
               }
            </script>
     </td>


<p>解説しなくても分かると思いますが、 onchangeとfunctionのところ。</p>

php 平凡なセレクトボックス

| コメント(0)

<select name="abcde">
                <option>選択してください</option>
                <option value="A">A</option>
                <option value="B">B</option>
                <option value="C">C</option>
                <option value="D">D</option>
                <option value="E">E</option>
                <option value="F">F</option>
                <option value="G">G</option>
                <option value="H">H</option>
                <option value="J">J</option>
                <option value="K">K</option>
                <option value="L">L</option>
                <option value="M">M</option>
                <option value="N">N</option>
                <option value="P">P</option>
                <option value="Q">Q</option>
                <option value="R">R</option>
                <option value="S">S</option>
                <option value="T">T</option>
                <option value="V">V</option>
                <option value="X">X</option>
                <option value="Y">Y</option>
                <option value="Z">Z</option>
  </select>

php 年度セレクトボックス

| コメント(0)

<select name="year" id="YDate">
                        <?php
                            $now = time();
                            for ($i=-1; $i<=5; $i++) {
                           $YDate = date("Y", strtotime("-{$i}year"));
                           print('<option value="'. $YDate. '">'. $YDate. '</option>'. "\n");
                            }
                       ?>

</select>年

php selectbox あれこれ

| コメント(0)

 //選択済み

<?php

        $sql = "SELECT id,name FROM makers order by id";
        $result = executeQuery($sql);
    echo "<select name=\"maker_id\">";
    echo "<option selected = true value = ".$prefMaker.">$prefMname</option>";
    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
    echo "<option value=\"".$row["id"]."\">"."【".$row["id"]."】".":".$row["name"]."</option>";
    }
    echo "</select>";
 ?>
//選択してください
<?php
    $sql = "SELECT id,name FROM suppliers order by name";
   $result = executeQuery($sql);
   echo "<select name=\"supplier_id\">";
   echo "<option>選択してください</option>";
   while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
   echo "<option value=\"".$row["id"]."\">"."【".$row["id"]."】".":".$row["name"]."</option>";
   }
   echo "</select>";
 ?>
 //セレクトボックスの幅指定したいとき
   echo "<select  style=\"width:70%;\" name=\"id\">";//セレクトボックスの幅
//セレクトボックスで選択したIDから、一旦関連データを取得してPOSTする
//アクションは、コード書き込みしてある同じファイルを指定する

<form action="./maintenance_detail_insert.php" method="post">

<?php

              $sql2 = "SELECT id,code FROM charge where code like 'F%' order by id";

              $result2 = executeQuery($sql2);

              echo "<select name=\"chid\">";

              echo "<option>選択してください</option>";

              while ($row = mysql_fetch_array($result2, MYSQL_ASSOC)){

              echo "<option value=\"".$row["id"]."\">"."【".$row["id"]."】".":".$row["code"]."</option>";

              }

              echo "</select>";

 ?>

 <input type="submit" name="submit" value="データ取得">

</form>

 

//変数への代入処理

<?php
             if(@$_POST['chid'] == ""){
                 $prefChid = "";
                 $prefMid = "";
                 $prefMname = "";
                 $prefCatarog = "";
                 $prefSpec = "";
                 $prefPrice = "";
             }else{
                 $prefChid = $_POST['chid'];
                 $sql3 = "SELECT *,makers.name as mname FROM charge";
                 $sql3 .= " join makers on charge.maker_id = makers.id where charge.id = ".$prefChid;
                 $result3 = executeQuery($sql3);
                 while($row3 = mysql_fetch_array($result3)){
                     $prefMid = $row3['maker_id'];
                     $prefMname = $row3['mname'];
                     $prefCatarog = $row3['catarog'];
                     $prefSpec = $row3["spec"];
                     $prefPrice = $row3["price"];
                 }
             }
?> 

 

//下記で値取得する

<form action="./maintenance_detail_insert2.php" method="post">
     <input type="hidden" name="chcd_id" value="<?= $prefChid ?>">
     <input type="hidden" name="catarog" value="<?= $prefCatarog ?>">
     <input type="hidden" name="spec" value="<?= $prefSpec ?>">
     <input type="hidden" name="maker_id" value="<?= $prefMid ?>">
     <input type="hidden" name="price" value="<?= $prefPrice ?>">
   
          <table class="slip">
           <th style="width:80px;">品名</th>
           <td style="width:360px;">
               <?= $prefCatarog ?>
           </td>
           </table>
           <table class="slip">        
           <th style="width:80px;">仕様・規格</th>
           <td style="width:360px;">
               <?= $prefSpec ?>
           </td>
           </table>
          <table class="slip">
          <th style="width:80px;">メーカー</th>
          <td style="width:360px;">
               <?= $prefMname ?>
           </td>
           </table>
           <table class="slip">
          <th style="width:80px;">単価</th>
          <td style="width:360px;">
               <?= $prefPrice ?>
           </td>
           </table>
           <table class="slip">
           <th>数量</th>
           <td align = 'right'>
                <input type="text" size="11" name="volume" style="ime-mode:disabled" value="">
           </td>
           </table>

</form>