我想通過隱藏的iframe動態地將選項添加到列表中;我懷疑我的錯誤是在下面的PHP:通過隱藏的iframe動態地將選項添加到列表中
<?php echo 'var oInner = document.createTextNode("'.$donnees["name"].'");'; ?>
,因爲我的代碼工作完美搭配:
<?php echo 'var oInner = document.createTextNode("Newoption");'; ?>
我不知道爲什麼一個createTextNode不希望把我的PHP變種...我認爲這可能是一個相同的原產地策略,因爲數據庫位於我網站外的服務器上。
我不知道。
,你會發現封閉的完整代碼:
在我的HTML我有:
//select or change a country will trigger the javascript part
<select name="countrym" id="countrym" onchange="validcountry();">
<option value"France">France</option>
</select>
//Empty region list
<select name="regionm" id="regionm">
</select>
//My Iframe
<iframe name="upload_iframe2" id="upload_iframe2" frameborder="0"></iframe>
在我的JavaScript,我有:
//My function triggering the PHP through the Iframe
function validcountry() {
var countrym = document.getElementById('countrym');
var choixco = countrym.options[countrym.selectedIndex].value;
document.getElementById('upload_iframe2').src = 'region.php?choix='+choixco;
在我的PHP文件region.php ,我有:
<?php
// Get my choice
$codepays = $_GET['choix'];
//Retrieve the regions corresponding to the country
$pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
$bdd = new PDO(XXX);
$req = $bdd->prepare('SELECT name FROM regions WHERE country = :country');
$req->execute(array('country' => $codepays));
$donnees = $req->fetch();
while($donnees)
{
// I checked the format of the data (no problem so far)
echo var_dump ($donnees['name']);
?>
//I add an option through Javascript
<script language="JavaScript" type="text/javascript">
var oOption = document.createElement("option");
//Here is my big issue:
<?php echo 'var oInner = document.createTextNode("'.$donnees["name"].'");'; ?>
oOption.value = "none";
oOption.appendChild(oInner);
var parDoc = window.parent.document;
var regionm = parDoc.getElementById("regionm");
regionm.appendChild(oOption);
</script>
<?php
$donnees = $req->fetch();
}
$req->closeCursor();
exit();
?>
你能包括$最近搜索的的var_dump內容? – ContextSwitch 2012-04-28 18:21:39
當然。對於愛爾蘭,我有:字符串(7)「Carlow」字符串(6)「Cavan」字符串(6)「Clare」字符串(5)「軟木」字符串(8)「Donegal」字符串(7)「Dublin」字符串7)「Galway」串(6)「Kerry」串(8)「Kildare」串(9)「Kilkenny」串(6)「Laois」串(8)「Leitrim」串(9)「Limerick」串)「Longford」串(6)「Louth」串(5)「Mayo」串(6)「Meath」串(9)「Monaghan」串(7)「Offaly」串(10)「Roscommon」串(6) 「Sligo」字符串(10)「Tipperary」字符串(10)「Waterford」字符串(10)「Westmeath」字符串(8)「Wexford」字符串(8)「Wicklow」 – user1157439 2012-04-28 18:23:39
你看過你的JS檢查器)看看你的PHP渲染的JS語句是否有問題? – halfer 2012-04-28 23:30:25