Hi,
It is my 1st attempt with Ajax and I'm facing some problems. Below parts of my code. First part is working ok. But then I need to get option id attribute instead of value. And it is not working. Could you help me and check it? Thx
index.php form
<select name="client_name" id="client_data" onchange="ajaxFunction5()">
<option value="".$partner_name."">".$partner_name."</option>
</select>
ajax_select_box.js
function ajaxFunction5(){
var ajaxRequest; // magic variable
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
// Receive Data Function
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
var ajaxDisplay = document.getElementById('ajaxDiv5');
ajaxDisplay.innerHTML = ajaxRequest.responseText;
}
}
var client_data = document.getElementById('client_data').value;
var queryString = "?client_data=" + client_data;
ajaxRequest.open("GET", "contact_data.php" + queryString, true);
ajaxRequest.send(null);
}
contact_data.php
$client_data = $_GET['client_data'];
<select name="contact_name" id="contact_data"onchange="ajaxFunction4()">
// ======================== Here goes mysql_query
$wynik2 = mysql_query("SELECT partner_id, partner_name, contact_name FROM $sql_tabela WHERE partner_name LIKE '".$client_data."'");
while ($row = mysql_fetch_array($wynik2)) {
$partner_id = intval($row['partner_id']);
$contact_name = $row['contact_name'];
<option id="$partner_id" value="$contact_name"> $contact_name </option>
}
</select>
ajax_select[...]
function ajaxFunction4(){
[...]// ======================== Here the problem starts
[B]var contact = document.getElementById('contact_data');
var contact_data = contact.options[contact.selectedIndex].id;
var queryString = "?contact_data=" + contact_data;
ajaxRequest.open("GET", "client_data.php" + queryString, true);
ajaxRequest.send(null);[/B]
}
client_data.php
$contact_data = $_GET['contact_data'];
// ======================== Here goes 2nd mysql_query
$wynik2 = mysql_query("SELECT partner_id, partner_name, partner_address, partner_post, partner_city, contact_name, contact_phone,
contact_email FROM $sql_tabela WHERE partner_id='".$contact_data."'");