Hi Friends
I am trying to get the value of select dropdown item in a text box, but i am unable to get it. I am using ajax for dropdowm method.
please any one can help
one.php
<?php
session_start();
include("config.php");
// Check, if username session is NOT set then this page will jump to login page
if (!isset($_SESSION['username'])) {
header('Location: index.php');
}
include('func.php');
?>
<script language = javascript>
$(document).ready(function() {
$('#wait_1').hide();
$('#category_code').change(function(){
$('#wait_1').show();
$('#result_1').hide();
$.get("func.php", {
func: "category_code",
drop_var: $('#category_code').val()
}, function(response){
$('#result_1').fadeOut();
setTimeout("finishAjax('result_1', '"+escape(response)+"')", 400);
});
return false;
});
});
function finishAjax(id, response) {
$('#wait_1').hide();
$('#'+id).html(unescape(response));
$('#'+id).fadeIn();
}
</script>
<select name="category_code" id="category_code">
<option value="" selected="selected" disabled="disabled">Select Category Title</option>
<?php getTierOne(); ?>
</select>
<span id="wait_1" style="display: none;">
<img alt="Please Wait" src="images/ajax-loader.gif"/></span>
<span id="result_1" style="display: none;"></span>
func.php
<?php
//**************************************
// Page load dropdown results //
//**************************************
include_once('config.php');
function getTierOne()
{
$result = mysql_query("SELECT * FROM category_title")
or die(mysql_error());
while($tier = mysql_fetch_array( $result ))
{
echo '<option value="'.$tier['category_code'].'">'.$tier['category_title'].'</option>';
}
}
//**************************************
// First selection results //
//**************************************
if($_GET['func'] == "category_code" && isset($_GET['func'])) {
category_code($_GET['drop_var']);
}
function category_code($drop_var)
{
$result = mysql_query("SELECT * FROM category_item WHERE category_code='$drop_var'") or die(mysql_error());
echo '<select name="item_name" id="item_name">';
while($drop_2 = mysql_fetch_array( $result ))
{
echo '<option value="'.$drop_2['item_code'].'">'.$drop_2['category_item'].'</option>';
}
echo '</select>';
echo '<input type="text" name="item_name" value="'.$drop_2['category_item'].'" readonly="readonly">';
}
?>