2015-05-15 52 views
3
<?php 
    $sql = "select * from letter where societyn='" . $_SESSION['socityname'] ."' "; 
    $result = mysql_query($sql); 
    $i=1; 
    while($row=mysql_fetch_array($result)){   
?> 
<?php 
    $id = $row['id']; 
    $dater = $row['date']; 
    $flatnonam = $row['flatno_name']; 
    $addr = $row['adress']; 
    $subject = $row['subject']; 
    $body = $row['body']; 
    $soci = $row['societyn']; 
    $refnum = $row['refno']; 
    $letterh = $row['letterh']; 

     // split "dd-mm-yyyy" into an array of three elements 
     $ddate = explode("-", $dater); 
     // retrieve the values 
     $month = $ddate[1]; // mm 
     $day = $ddate[2]; // dd 
     $year = $ddate[0]; // yyyy 
    { 
    ?> 

<tr> 
      <td><?php echo $day.'/'.$month.'/'.$year; ?></td> 
      <td><?php echo $flatnonam; ?></td> 
      <td><?php echo $letterh; ?></td> 
      <td><?php echo $addr; ?></td> 
      <td><?php echo $subject; ?></td> 
      <td><?php echo $soci; ?></td> 
      <td><?php echo '#'.$refnum; ?></td> 

      <td> 
      <select name="menu1" id="menu1"> 
       <option value="" selected>Pick a Website</option> 
       <option value="letter/letter_print.php?id=<?php echo $row['id']; ?>">Without Letter Head</option> 
       <option value="letter/letter_print_nohead.php?id=<?php echo $row['id']; ?>">Letter Head</option> 
      </select> 
      </td></tr> 

    <?php }?> 
    <?php 
    echo "<br>"; 
    $i++; 
    } 

    ?> 


<!--This is java script--> 
<script type="text/javascript"> 
var urlmenu = document.getElementById('menu1'); 
urlmenu.onchange = function() { 
     window.open(this.options[ this.selectedIndex ].value, '_blank','width=595,height=842,directories=no,titlebar=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no'); 
}; 
</script> 

這是我的代碼.only第一個選項工作其他不工作。 請幫我解決麻煩。從2天起。或者給出另一個解 在一個ID如何使用所有選項。我試圖從2天不工作。下拉選擇去url不工作在while循環php

+0

這是我的查詢screenshoot:HTTP://我.stack.imgur.com/hk6ad.jpg –

+1

ID是唯一的,JS與第一個一起工作,如果頁面中有更多相同的ID。 – panther

+0

不能準確得到你想要做的?你正在重定向的網址是 –

回答

1

如上所述,將id更改爲class,因爲您有多個select。然後定義onchange監聽所有的人:

var urlmenus = document.querySelectorAll('.menu1'); 
for(var i = 0; i < urlmenus.length; i++) { 
    urlmenus[i].onchange = function() { 
     window.open(this.options[this.selectedIndex].value, '_blank', 'width=595,height=842,directories=no,titlebar=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no'); 
    }; 
} 

jsfiddle DEMO

+0

關於更改爲html,請給我建議,我更新鮮 –

+0

thnxxxxxxxxxx它工作 –

+0

非常感謝你很多 –

1

將這個代碼,並嘗試

$(document).ready(function() { 
 
     $("#menu1").change(function() { 
 
      var val1 = $(this).val(); 
 
      window.open(val1, '_blank'); 
 
     }); 
 

 
    })
<form> 
 

 
    <select name="menu1" id="menu1"> 
 
     <option value="" selected>Pick a Website</option> 
 
     <option value="letter/letter_print.php?id=<?php echo $row['id']; ?>">Without Letter Head</option> 
 
     <option value="letter/letter_print_nohead.php?id=<?php echo $row['id']; ?>">Letter Head</option> 
 
    </select> 
 
</form>