1
자바 스크립트를 사용하여 MySQL 결과에 따라 드롭 다운 목록을 업데이트하는 PHP 페이지가 있습니다. 내 문제는 JavaScript 변수를 통해 고객 이름을 전달할 때 첫 번째 공백에서 자르다는 것입니다. 예 : '집 창고'가 '집'으로 표시되거나 '홈 스토어'가 'The'로 표시됩니다. 적절한 쿼리를 실행하기 위해 전체 문자열을 전달하고 싶습니다. 문자열을 파일 cdd.php 내에서 다시자바 스크립트 변수 공백 후 잘림
<?
$Cust_ID = $_GET['custid'];
include('../Includes/TrackingDB.php');
mysql_connect($dbhost,$dbuser,$dbpass) or die('Error connecting to mysql');
mysql_select_db($dbdb) or die('Error connecting to database');
$query="SELECT t1.ContName FROM Cust_Contacts t1 INNER JOIN Customer_Listing t2 ON t1.Cust_ID = t1.Cust_ID WHERE t2.Name = '$Cust_ID'";
$result=mysql_query($query);
mysql_close();
echo var_dump($Cust_ID); //I added this solely for the purposes of trouble shooting this issue. This is where I am seeing the truncated string.
?>
<select name="Cust_Buyer" onchange="getCity(<?=$country?>,this.value)">
<? while($row=mysql_fetch_array($result)) { ?>
<option value="<?=$row['ContName']?>"><?=$row['ContName']?></option>
<? } ?>
</select>
을 공백을 잘라냅니다 :
function getXMLHTTP() { //function to return the xml http object
var xmlhttp=false;
try{
xmlhttp=new XMLHttpRequest();
}
catch(e) {
try{
xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e){
try{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e1){
xmlhttp=false;
}
}
}
return xmlhttp;
}
function getCustCont(cID)
{
var strURL="Includes/cdd.php?custid="+cID;
var req = getXMLHTTP();
if (req)
{
req.onreadystatechange = function()
{
if (req.readyState == 4)
{
// only if "OK"
if (req.status == 200)
{
document.getElementById('Contdiv').innerHTML=req.responseText;
} else {
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
//VARIABLES DEFINED AND START OF FORM
<td width="60%">
<select name="Customer" onchange="getCustCont(this.value)">
<option value="SAC">Select Customer</option>
<?php
$i=0;
while ($i < $num) {
$Name=mysql_result($result,$i,"Name");
echo "<option value=$Name>$Name</option>";
$i++;
}
?>
</select>
</td>
cdd.php 파일은 다음과 같습니다 여기
은 내 양식에서 관련 코드 .
당신은 신사 학자 있습니다. . . 매력처럼 일했다. 고맙습니다! – user1459766
고맙습니다! – KapteinMarshall