我有作爲數組傳遞到URL和頁面重新加載的複選框我應該讓它們回來以便檢查所檢查的內容。
這裏是我的javascript,陣列中的問題是 'entry_reason':
<script language="JavaScript">
<!--
function reload(nname, surname, birth_date, birth_country, birth_place, postal_code, address, residence, oib, license_number, license_iplace, passport_number, passport_iplace, entry_reason, myself, myselfeng)
{
// Setting the variable with the value of selected country's ID
var nname=document.getElementById('nname').value;
var surname=document.getElementById('surname').value;
var birth_date=document.getElementById('birth_date').value;
var c=document.getElementById('birth_country').value;
var city=document.getElementById('birth_place').value;
var postal_code=document.getElementById('postal_code').value;
var address=document.getElementById('address').value;
var residence=document.getElementById('residence').value;
var oib=document.getElementById('oib').value;
var license_number=document.getElementById('license_number').value;
var license_iplace=document.getElementById('license_iplace').value;
var passport_number=document.getElementById('passport_number').value;
var passport_iplace=document.getElementById('passport_iplace').value;
var entry_reason=[document.getElementById('entry_reason1').value, document.getElementById('entry_reason2').value, document.getElementById('entry_reason3').value, document.getElementById('entry_reason4').value, document.getElementById('entry_reason5').value, document.getElementById('entry_reason6').value, document.getElementById('entry_reason7').value];
var myself=document.getElementById('myself').value;
var myselfeng=document.getElementById('myselfeng').value;
// Sending the country id in the query string to retrieve the city list
self.location='blacklistprivateregister.php?nname=' + nname + '&surname=' + surname + '&birth_date=' + birth_date + '&birth_country=' + c + '&birth_place=' + city + '&postal_code=' + postal_code + '&address=' + address + '&residence=' + residence + '&oib=' + oib + '&license_number=' + license_number + '&license_iplace=' + license_iplace + '&passport_number=' + passport_number + '&passport_iplace=' + passport_iplace + '&entry_reason[]=' + entry_reason + '&myself=' + myself + '&myselfeng=' + myselfeng;
}
-->
</script>
我得到URL看起來是這樣的:
http://xxxxxxxx.php?nname=ivo&surname=&birth_date=2012-11-08&birth_country=Algeria&birth_place=Benguela&postal_code=10000&address=%C4%8Ci%C4%8Dkovina%20222&residence=Zagorne&oib=1231231232131&license_number=21312323213&license_iplace=Zagreb&passport_number=000493243244&passport_iplace=Vara%C5%BEdin&entry_reason[]=1,2,3,4,5,6,7&myself=aasddsad&myselfeng=asdadasd
將與我的輸入複選框是這樣的:
<legend><?php echo REASONFORENTRY_R; ?></legend>
<?php
$e=array();
if(isset($_POST['entry_reason'])){ $e=$_POST['entry_reason'];}
if($_GET['entry_reason']) {$e=$_GET['entry_reason'];}
?>
<p><input type="checkbox" name="entry_reason[]" id="entry_reason1" class="check" value="1" <?php if(in_array('1', $e)) echo 'checked="checked" '; ?>/><?php echo ER1_R; ?></p>
<p><input type="checkbox" name="entry_reason[]" id="entry_reason2" class="check" value="2" <?php if(in_array('2', $e)) echo 'checked="checked" '; ?>/><?php echo ER2_R; ?></p>
<p><input type="checkbox" name="entry_reason[]" id="entry_reason3" class="check" value="3" <?php if(in_array('3', $e)) echo 'checked="checked" '; ?>/><?php echo ER3_R; ?></p>
<p><input type="checkbox" name="entry_reason[]" id="entry_reason4" class="check" value="4" <?php if(in_array('4', $e)) echo 'checked="checked" '; ?>/><?php echo ER4_R; ?></p>
<p><input type="checkbox" name="entry_reason[]" id="entry_reason5" class="check" value="5" <?php if(in_array('5', $e)) echo 'checked="checked" '; ?>/><?php echo ER5_R; ?></p>
<p><input type="checkbox" name="entry_reason[]" id="entry_reason6" class="check" value="6" <?php if(in_array('6', $e)) echo 'checked="checked" '; ?>/><?php echo ER6_R; ?></p>
<p><input type="checkbox" name="entry_reason[]" id="entry_reason7" class="check" value="7" <?php if(in_array('7', $e)) echo 'checked="checked" '; ?>/><?php echo ER7_R; ?></p>
我在網站上有3個動作,其中2個我想讓複選框被記住: 1)頁上的javascript函數重載 2)頁面重新加載錯誤提交重裝 - 這一個適用於現在$ _ POST
我相信,對於第一次重裝我應該從URL所有變量項目到$ _GET和通他們到$ e變量,但它似乎並沒有工作。
所有幫助表示讚賞!
沒有違法,但你有沒有聽說過循環?你知道'