2013-12-21 46 views
0

所以基本上可以說我有稱爲頁頁面與-links.phpPHP:<a>標籤的郵政名稱,然後掛在網頁上使用


<ul> 
    <li><a href="page-with-checkboxes.php" name="blue">Blue</a></li> 
    <li><a href="page-with-checkboxes.php" name="red">Red</a></li> 
    <li><a href="page-with-checkboxes.php" name="green">Green</a></li> 
    <li><a href="page-with-checkboxes.php" name="yellow">Yellow</a></li> 
    <li><a href="page-with-checkboxes.php" name="orange">Orange</a></li> 
</ul> 


和一頁叫做page-with-checkboxes.php

<h3>You selected:</h3> 

<form> 
    <input type="checkbox" name="blue" /> 
    <label for="blue"> Blue</label><br> 

    input type="checkbox" name="red" /> 
    <label for="red"> Red</label><br> 

    input type="checkbox" name="green" /> 
    <label for="green"> Green</label><br> 

    <input type="checkbox" name="yellow" /> 
    <label for="yellow"> Yellow</label><br> 

    <input type="checkbox" name="orange" /> 
    <label for="orange"> Orange</label><br> 
</form> 



我想能夠使用<a>標籤的名稱值來檢查下一個頁面上的相關框。

例如,如果用戶點擊「綠色」頁面與-links.php,我想用複選框以name="green"檢查時頁面與-checkboxes.php負載。

我希望我已經清楚了。在此先感謝任何可以幫助的人!

回答

0

寫線在頁面上頁面與-links.php

<ul> <li> <a href="page-with-checkboxes.php?value=blue" name="blue">Blue</a> </li> <li> <a href="page-with-checkboxes.php?value=red" name="red">Red</a></li> <li> <a href="page-with-checkboxes.php?value=green" name="green">Green</a></li> <li> <a href="page-with-checkboxes.php?value=yellow" name="yellow">Yellow</a></li> <li> <a href="page-with-checkboxes.php?value=orange" name="orange">Orange</a></li> </ul>

,寫遵循網頁上的代碼行稱爲頁面與-checkboxes.php:

<input type="checkbox" name="blue" <?php echo $_GET['value']=='blue'?'checked':''; /> <label for="blue"> Blue</label><br> <input type="checkbox" name="red" <?php echo $_GET['value']=='red'?'checked':''; /> <label for="red"> Red</label><br> <input type="checkbox" name="green" <?php echo $_GET['value']=='green'?'checked':''; /> <label for="green"> Green</label><br> <input type="checkbox" name="yellow" <?php echo $_GET['value']=='yellow'?'checked':''; /> <label for="yellow"> Yellow</label><br> <input type="checkbox" name="orange" <?php echo $_GET['value']=='orange'?'checked':''; /> <label for="orange"> Orange</label>

0

你可以試試這個,

在頁面與-links.php:

<li><a href="page-with-checkboxes.php?type=blue" name="blue">Blue</a></li> 

在頁面與-checkboxes.php:

<input type="checkbox" name="blue" <?php echo $_GET['type']=='blue'?'checked':''; /> 
<label for="blue"> Blue</label><br> 
1

a標籤的屬性呢不影響請求。

您必須遵循這樣的:

<ul> 
    <li><a href="page-with-checkboxes.php?name=blue" name="blue">Blue</a></li> 
    <li><a href="page-with-checkboxes.php?name=red" name="red">Red</a></li> 
    <li><a href="page-with-checkboxes.php?name=green" name="green">Green</a></li> 
    <li><a href="page-with-checkboxes.php?name=yellow" name="yellow">Yellow</a></li> 
    <li><a href="page-with-checkboxes.php?name=orange" name="orange">Orange</a></li> 
</ul> 

而在你page-with-checkboxes.php得到這個值:代碼

<?php 
    if(isset($_GET['name']) { 
     $color = $_GET['name']; 
    } else { 
     $color = null; 
    } 
?> 

<form> 
    <input type="checkbox" name="blue" <?php print $color=="blue" ? "checked" : "" ?> /> 
    <label for="blue"> Blue</label><br> 

    input type="checkbox" name="red" <?php print $color=="red" ? "checked" : "" ?> /> 
    <label for="red"> Red</label><br> 

    input type="checkbox" name="green" <?php print $color=="green" ? "checked" : "" ?> /> 
    <label for="green"> Green</label><br> 

    <input type="checkbox" name="yellow" <?php print $color=="yellow" ? "checked" : "" ?> /> 
    <label for="yellow"> Yellow</label><br> 

    <input type="checkbox" name="orange" <?php print $color=="orange" ? "checked" : "" ?> /> 
    <label for="orange"> Orange</label><br> 
</form> 
+0

不能得到這個出於某種原因...方法發表@SiwachGaurav偉大的工作,但我更喜歡你的方法,而不是使用多個'$ _GET'請求。任何想法我可能錯過了什麼?請注意,我在一些「輸入」字段中添加了缺失的V形符號,仍然無法使其工作,所以這不是問題。謝謝 – Ross

+0

哦,我錯過了打印功能,請原諒! – Mohebifar