PDA

View Full Version : سوال: مشکل در گرفتن مقدار از یک DropDownList



kinia111
شنبه 22 تیر 1392, 11:30 صبح
باسلام و وقت بخیر

یه سوال داشتم من دوتا DropDownList دارم که اولی در مورد موضوعات(سرشاخه) است که وقتی روی اولی کلیک می‌کنیم DropDownList دومی را که شامل زیرمجموعه‌ای از اولی(زیرشاخه) است ظاهر می‌شود من می‌خواهم وقتی DropDownList دومی ظاهر شد و کاربر روی هرکدام از optionهاش کلیک کرد اطلاعات مربوط به آن option را نمایش دهد ولی متاسفانه این قسمت آخر (که اطلاعات مربوط به option انتخاب شده را نمایش دهد) را نمی‌تونم در بیارم ممنون می‌شم اگر راهنمایی کنید.





<label for="subject_name">انتخاب موضوع</label>
<script type="text/javascript">

var time_variable;

function getXMLObject() //XML OBJECT
{
var xmlHttp = false;
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP") // For Old Microsoft Browsers
}
catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP") // For Microsoft IE 6.0+
}
catch (e2) {
xmlHttp = false // No Browser accepts the XMLHTTP Object then false
}
}
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
xmlHttp = new XMLHttpRequest(); //For Mozilla, Opera Browsers
}
return xmlHttp; // Mandatory Statement returning the ajax object created
}

var xmlhttp = new getXMLObject(); //xmlhttp holds the ajax object

function ajaxFunction() {
var getdate = new Date(); //Used to prevent caching during ajax call
if(xmlhttp) {
var pid = document.getElementById("title").value;
xmlhttp.open("POST","title.php",true); //calling testing.php using POST method
xmlhttp.onreadystatechange = handleServerResponse;
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.send("pid=" + pid); //Posting txtname to PHP File
}
}

function handleServerResponse() {
if (xmlhttp.readyState == 4) {
if(xmlhttp.status == 200) {
document.getElementById("message").innerHTML=xmlhttp.responseText; //Update the HTML Form element
}
else {
alert("Error during AJAX call. Please try again");
}
}
}
</script>


<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<br/>

<select name="subject" class="accordion-trigger" id="title" dir="rtl" onChange="ajaxFunction()" >
<option value="0">Please Select</option>


<?php
require('config/config.php');
$query = "select * from work where pid=0";
$results= mysql_query($query);
while ($row = mysql_fetch_array($results)) {
echo '<option value="'.$row["code_title"].'">'.$row["name_title"].'</option>';
}

?>
</select>
<br/>


<!--show subject information here !-->
<div id="message" name="message"></div>
</div>
<!-- ENDS entry-content -->
<?php
require('config/config.php');
$query="select *from notice where sub_name like '".$_POST['subject']."'";
$result=mysql_query($query);

while ($row=mysql_fetch_array($result)){

echo '<h4 >'.$row['title'].'</h4>';

echo $row['text'];
echo ' ______________ '. $row['tel'];

echo' <div class="one-fourth last" >
</div> ';
}
?>