0

コミュニティ、私は現在、mysql クエリを介して値とタイトルが入力されている選択ドロップダウンを持っています。現在、渡されているのは (source_id) だけです。ただし、2 番目の変数 (source_flag) も渡す必要があります。次の理由で両方が必要です。source_flag が「YES」に設定されている場合、私の JS は div を表示します。データベースに値を挿入するには、(source_id) が必要です。以下は、現在のドロップダウンと JS 関数です。HTML を少し追加します。

HTML

<fieldset style="display: inline;" id="source">
<legend class="legend1"><h2>&nbsp; Ticket Source &nbsp;</h2></legend>
<div style="padding-top: 5px;" id="source">
     <div class="input-field">
     <?php include $ins_tic.'selectSource'.$ext; ?>
     </div>
     <div id="received"  style="display: none;">
     <input type="text" id="dateTimeField" name="received_on" style="width: 160px;" placeholder="Time Received"/>
     <script>AnyTime.picker('dateTimeField');</script>
     </div>
</div>
</fieldset>

$ins_tic.'selectSource'.$ext ファイル

<?php
//This populates the drop down
echo '
<select id="ticket_source" name="ticket_source" tabindex="16" onchange="showEmail(this.value)">
<option value="">Select Source</option>';
//I want to add source_flag to the query, and add that value to the select option
$get_sources = mysql_query("SELECT source_id, source_name FROM ticket_source ORDER BY source_name ASC");
 while (($source_list = mysql_fetch_assoc($get_sources)))
 {
      echo '
      <option value="'.$source_list['source_id'].'">'.$source_list['source_name'].'</option>';
 };
 echo '
 <option value="0">Other</option>
 </select>';
 ?>

最後に、私の現在のjavascriptです。現在、javascript は source_id 値から外れていることに注意してください。追加のソースが将来追加される可能性があり、おそらく追加される可能性があるため、私はそのようにするのは嫌いです.

function showEmail(id)
{
    var div = document.getElementById("received");
    if(id == 2 || id == 3 || id == 5)
    {
        div.style.display = 'block';
    }
    else
    {
        div.style.display = 'none';
    }
}
4

2 に答える 2

1

どうですか:

<select id="ticket_source" name="ticket_source" tabindex="16" onchange="showEmail(this)">

に続く

  <option value="'.$source_list['source_id'].'" data-flag="'.$source_list['source_flag'].'>'.$source_list['source_name'].'</option>';

その後

function showEmail(element)
{
    var id = element.value;
    var flag = element.options[element.selectedIndex].getAttribute('data-flag');
    // Do something with flag...
    var div = document.getElementById("received");
    if(id == 2 || id == 3 || id == 5)
    {
        div.style.display = 'block';
    }
    else
    {
        div.style.display = 'none';
    }
}
于 2013-09-25T14:32:34.590 に答える
0

区切り文字を追加し、両方の値を に入れ<option>、サーバーで解析する必要があります。

 <option value="'.$source_list['source_id']._.$source_list['source_flag']'">
于 2013-09-25T14:30:40.483 に答える