私はしばらくの間、スクリプトに苦労しています。
オプション値変数 $varState (ドロップダウンボックスから) を mysql クエリに渡す/送信する方法を見つける必要があります。私はajaxを試しましたが、うまくいかないようです。
私の開発サイトで例を見つけることができ、私のコードは次のとおりです。
<form name="klassiek" >
<select name="landen" onChange="updateprovincie(this.selectedIndex)" style="width: 250px" >
<option value="">kies land</option>
<option value="NL">Nederland</option>
<option value="BE">Belgie</option>
<option value="ts">test</option>
</select>
<br />
<select name="provincie" id="provincie" action="/acceptatie/verkooppunten.html" method="post" size="4" style="width: 250px" onClick=" myVariable()" >
</select>
</form>
<br>
</head>
<body>
<script type="text/javascript">
var landenlist=document.klassiek.landen
var provincielist=document.klassiek.provincie
var provincie=new Array()
provincie[0]=""
provincie[1]=["Drenthe|drenthe", "Flevoland|flevoland", "Friesland|friesland", "Gelderland|gelderland", "Groningen|groningen", "Gelderland|gelderland", "Limburg|limburg","Noord Brabant|noordbrabant", "Noord Holland|noord holland", "Overijssel|overijssel", "Utrecht|utrecht", "Zeeland|zeeland", "Zuid Holland|zuidholland"]
provincie[2]=["Antwerpen|antwerpenvalue", "Limburg|limburgvalue", "Oost Vlaanderen|oostvlaanderenvalue", "Vlaams Brabant|vlaamsbrabantvalue", "West Vlaanderen|westvlaanderenvalue", "Waals Brabant|waalsbrabantvalue","Henegouwen|hennegouwenvalue","Luik|Luikvalue", "Luxemburg|Luxemburgalue","Namen|namenvalue"]
function myVariable(){
var state=document.getElementById('provincie').value;
//get value and pass to php script
document.write(state);//need to pass this value to php query
}
function updateprovincie(selectedprovinciegroup)
{
provincielist.options.length=0
if (selectedprovinciegroup>0)
{
for (i=0; i<provincie[selectedprovinciegroup].length; i++)
provincielist.options[provincielist.options.length]=new Option(provincie[selectedprovinciegroup][i].split("|")[0], provincie[selectedprovinciegroup][i].split("|")[1],provincie[selectedprovinciegroup][i].split("|")[2])
}
}
</script>
<br /><br />
<?php
$varState= $_POST["provincie"];
//print_r($varState);
$query3="SELECT * FROM jos_contact_details WHERE catid=80 && state = '$varState'" ;
$result=mysql_query($query3);
$num=mysql_numrows($result);
while($rec = mysql_fetch_assoc($result))
?>
<table border="0" cellspacing="2" cellpadding="2">
<tr>
<td><font face="Arial, Helvetica, sans-serif">Naam</font></td>
<td><font face="Arial, Helvetica, sans-serif">Adres</font></td>
<td><font face="Arial, Helvetica, sans-serif">Postcode</font></td>
<td><font face="Arial, Helvetica, sans-serif">Land</font></td>
<td><font face="Arial, Helvetica, sans-serif">Productgroep</font></td>
</tr>
<?php
$i=0;
while ($i < $num) {
$f1=mysql_result($result,$i,"name");
$f2=mysql_result($result,$i,"address");
$f3=mysql_result($result,$i,"state");
$f4=mysql_result($result,$i,"country");
$f5=mysql_result($result,$i,"productgroep");
?>
<tr>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f1; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f2; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f3; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f4; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f5; ?></font></td>
</tr>
<?php
$i++;
}
mysql_close();
//einde code
誰かが助けてくれることを願っています。
//ajaxcode in function myVariable()
function myVariable(str){ var
> state=document.getElementById('provincie').value; //get value and pass
> to php script //document.write(state);
>
>
> if (str=="") { document.getElementById("provincie").innerHTML="";
> return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox,
> Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {//
> code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
> } xmlhttp.onreadystatechange=function() { if
> (xmlhttp.readyState==4 && xmlhttp.status==200)
> {
> document.getElementById("provincie").innerHTML=xmlhttp.responseText;
> } } xmlhttp.open("GET","/acceptatie/verkooppunten.html?varState="+str,true);
> xmlhttp.send(); }
</script>