/    Sign up×
Community /Pin to ProfileBookmark

Php ajax dropdownlist problem

Hi, i have this problem regarding ajax dropdownlist. Here is my code.

this is my ajax code

[code]
function getXMLHTTP()
{
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 getIpt(strURL)
{

var req = getXMLHTTP();

if (req)
{

req.onreadystatechange = function()
{
if (req.readyState == 4)
{
// only if “OK”
if (req.status == 200)
{
document.getElementById(‘institusidiv’).innerHTML=req.responseText;
}
else
{
alert(“There was a problem while using XMLHTTP:n” + req.statusText);
}
}
}
req.open(“GET”, strURL, true);
req.send(null);
}
}

function getKursus(strURL)
{

var req = getXMLHTTP();

if (req)
{

req.onreadystatechange = function()
{
if (req.readyState == 4)
{
// only if “OK”
if (req.status == 200)
{
document.getElementById(‘kursusdiv’).innerHTML=req.responseText;
}
else
{
alert(“There was a problem while using XMLHTTP:n” + req.statusText);
}
}
}
req.open(“GET”, strURL, true);
req.send(null);
}
}
[/code]

Here is my php code (ajaxIPT.php)

[code]
<?php
require_once(“../../class/class.mysqldb.php”);
$code = intval($_REQUEST[‘code’]);
$kod_ins = $_REQUEST[‘kod_ins’];
$con = new MysqlDB;
$con->connectMysql();

if($code == 1)
{
$queryIpt = “select ctext from kod_ipt where kat_ipt = 1″;
$resultQuery = $con->query($queryIpt);
?>
<select name=”INSTITUSI” id=”INSTITUSI”>
<option>–Choose–</option>
<?php
while($row=$con->fetch_array($resultQuery))
{
?>
<option value=”<?php echo $row[‘ctext’]; ?>”><?php echo $row[‘ctext’]; ?></option>
<?php
}
?>
</select>
<?php
}
elseif($code == 2)
{
$queryIpt = “select ctext from kod_ipt where kat_ipt = 2″;
$resultQuery = $con->query($queryIpt);
?>
<select name=”INSTITUSI” id=”INSTITUSI”>
<option>–Choose–</option>
<?php
while($row=$con->fetch_array($resultQuery))
{
?>
<option value=”<?php echo $row[‘ctext’]; ?>”><?php echo $row[‘ctext’]; ?></option>
<?php
}
?>
</select>
<?php
}
elseif($code == 3)
{
?>
<input name=”INSTITUSI” type=”text” id=”INSTITUSI” size=”30″ value=”” />
<?php
}
elseif($code == 4)
{
?>
<input name=”INSTITUSI” type=”text” id=”INSTITUSI” size=”30″ value=”Test” />
<?php
}
?>
[/code]

And this is my form

[code]
<table width=”100%” cellspacing=”1″ class=”main”>
<tr>
<th width=”25%”>
<div align=”left”>
<strong>A</strong>
</div>
</th>
<th align=”center” width=”2%”>
<div align=”center”>:</div>
</th>
<td width=”73%” class=”bodystyle”>
<select name=”KOD_INSTITUSI” id=”KOD_INSTITUSI” onchange=”getIpt(‘ajaxIPT.php?code=’+this.value),tukarPeringkat(this.value);”>
<option value=””>-Choose-</option>
<?php
while($row=$con->fetch_array($resultIptQuery))
{
?>
<option value = “<?php echo $row[‘id’]; ?>”><?php echo $row[‘cat’]; ?></option>
<?php
}
?>
</select>
</td>
</tr>
<tr>
<th>
<div align=”left”>
<strong>B</strong>
</div>
</th>
<th align=”center”><div align=”center”>:</div></th>
<td class=”bodystyle”>
<div id=”institusidiv”>
<select name=”INSTITUSI” id=”INSTITUSI” onchange=””>
<option value=””>-Choose-</option>
</select>
</div>
</td>
</tr>
</table>
[/code]

this code works perfectly. When i choose KOD_INSTITUSI, the INSTITUSI dropdownlist change. The problem now is, when i post the form, the INSTITUSI IS NULL. It is like, the result in INSTITUSI dropdownlist only “virtually/temporarily”(sorry if im using wrong word ?) exist there not the real object. That’s y when i post the form, the INSTITUSI dropdownlist post NULL. I think maybe it is because the way i send data from ajaxIPT.php to the ajax code?? Hope someone out there can help me. Thanks in advance.

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @warhead2020 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...